From 23257d8c6349966934b4441ee85a797030d5160d Mon Sep 17 00:00:00 2001 From: keyan Date: Fri, 4 Aug 2023 12:07:44 -0500 Subject: [PATCH] fix notifications glitchiness --- components/notifications.js | 10 +++++----- lib/apollo.js | 1 - pages/_app.js | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/notifications.js b/components/notifications.js index c4a352d4..f6b348f4 100644 --- a/components/notifications.js +++ b/components/notifications.js @@ -42,9 +42,9 @@ function NotificationLayout ({ children, nid, href, as }) { return (
{ + onClick={async (e) => { if (ignoreClick(e)) return - nid && router.replace({ + nid && await router.replace({ pathname: router.pathname, query: { ...router.query, @@ -348,8 +348,7 @@ export default function Notifications ({ ssrData }) { nodata: true, // make sure nodata is set so we don't fetch on back/forward checkedAt: lastChecked } - }, - router.asPath, { ...router.options, shallow: true }) + }, router.asPath, { ...router.options, shallow: true }) client?.writeQuery({ query: HAS_NOTIFICATIONS, data: { @@ -361,8 +360,9 @@ export default function Notifications ({ ssrData }) { const [fresh, old] = useMemo(() => { if (!notifications) return [[], []] + const freshTime = checkedAt || lastChecked return notifications.reduce((result, n) => { - result[new Date(n.sortTime).getTime() > new Date(checkedAt)?.getTime() ? 0 : 1].push(n) + result[new Date(n.sortTime).getTime() > new Date(freshTime)?.getTime() ? 0 : 1].push(n) return result }, [[], []]) diff --git a/lib/apollo.js b/lib/apollo.js index 665c533e..83f36b12 100644 --- a/lib/apollo.js +++ b/lib/apollo.js @@ -29,7 +29,6 @@ function getClient (uri) { return new ApolloClient({ link: new HttpLink({ uri }), ssrMode: SSR, - ssrForceFetchDelay: 100, cache: new InMemoryCache({ freezeResults: true, typePolicies: { diff --git a/pages/_app.js b/pages/_app.js index 4914287b..b29475d9 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -25,7 +25,6 @@ function writeQuery (client, apollo, data) { query: gql`${apollo.query}`, data, variables: apollo.variables, - broadcast: !SSR, overwrite: SSR }) }