Skip to content

Commit

Permalink
Fix error on page transition with multiple queries (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewilson authored Jan 17, 2024
1 parent 7764c37 commit 1b495d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-walls-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/core': patch
---

Fixes a bug when navigating to a page client side that threw an error with multiple queries.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion packages/faustwp-core/src/components/FaustProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { ApolloProvider } from '@apollo/client';
// eslint-disable-next-line import/extensions
import { useRouter } from 'next/router';
Expand Down Expand Up @@ -37,6 +37,15 @@ export function FaustProvider(props: {
setQueries,
});

/**
* On page transitions, reset the queries state based on the new page props.
*/
useEffect(() => {
// eslint-disable-next-line no-underscore-dangle
if (pageProps.__FAUST_QUERIES__) setQueries(pageProps.__FAUST_QUERIES__);
// eslint-disable-next-line no-underscore-dangle
}, [pageProps.__FAUST_QUERIES__]);

return (
<FaustContext.Provider value={faustContext}>
<ApolloProvider client={apolloClient}>
Expand Down

0 comments on commit 1b495d7

Please sign in to comment.