Skip to content

Commit

Permalink
chore(next): warn for missing suspense boundary (#3449)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Dec 6, 2023
1 parent f39165d commit fa692c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/small-rings-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/next': patch
---

Show a warning when the `Suspense` boundary is missing under the UrqlProvider
19 changes: 18 additions & 1 deletion packages/next-urql/src/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export const SSRContext = React.createContext<SSRExchange | undefined>(
undefined
);

const SuspenseWarning = () => {
if (process.env.NODE_ENV !== 'production') {
console.warn(
'urql suspended but there was no boundary to catch it, add a <Suspense> component under your urql Provider.'
);
}
return null;
};

/** Provider for `@urql/next` during non-rsc interactions.
*
* @remarks
Expand Down Expand Up @@ -59,7 +68,15 @@ export function UrqlProvider({
React.createElement(
SSRContext.Provider,
{ value: ssr },
React.createElement(DataHydrationContextProvider, { nonce }, children)
React.createElement(
DataHydrationContextProvider,
{ nonce },
React.createElement(
React.Suspense,
{ fallback: React.createElement(SuspenseWarning) },
children
)
)
)
);
}

0 comments on commit fa692c1

Please sign in to comment.