From 39852c829751c259056247ba13d01e6b6524392b Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 26 Aug 2022 16:03:47 -0700 Subject: [PATCH] Oops, fix a bug where incorrect login closed modal Oh yeah, ok, we don't actually want to evict `currentUser` from the Apollo cache on *any* login mutation. That's both inefficient, and puts our navbar in a loading state that hides the login button and thereby unmounts the login modal, oops! --- src/app/components/LoginModal.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/components/LoginModal.js b/src/app/components/LoginModal.js index 200e24e..c8d3cf2 100644 --- a/src/app/components/LoginModal.js +++ b/src/app/components/LoginModal.js @@ -78,11 +78,11 @@ function LoginForm({ onSuccess }) { // I don't do any optimistic UI here, because auth is complex enough // that I'd rather only show login success after validating it through // an actual server round-trip. - cache.evict({ id: "ROOT_QUERY", fieldName: "currentUser" }); if (data.login?.id != null) { + cache.evict({ id: "ROOT_QUERY", fieldName: "currentUser" }); cache.evict({ id: `User:${data.login.id}` }); + cache.gc(); } - cache.gc(); }, } ); @@ -99,7 +99,7 @@ function LoginForm({ onSuccess }) { onSuccess(); } }) - .catch((e) => {}); // handled in error UI + .catch((e) => console.error(e)); // plus the error UI }} >