Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on page transition with multiple queries #1737

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading