the-forest/client/node_modules/.cache/babel-loader/0dad90054820e528f5849bf0689dde303d06db07d8df984e26b0129396db65ce.json

1 line
8.1 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"\"use client\";\n\n// src/HydrationBoundary.tsx\nimport * as React from \"react\";\nimport { hydrate } from \"@tanstack/query-core\";\nimport { useQueryClient } from \"./QueryClientProvider.js\";\nvar HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient\n}) => {\n const client = useQueryClient(queryClient);\n const [hydrationQueue, setHydrationQueue] = React.useState();\n const optionsRef = React.useRef(options);\n optionsRef.current = options;\n React.useMemo(() => {\n if (state) {\n if (typeof state !== \"object\") {\n return;\n }\n const queryCache = client.getQueryCache();\n const queries = state.queries || [];\n const newQueries = [];\n const existingQueries = [];\n for (const dehydratedQuery of queries) {\n const existingQuery = queryCache.get(dehydratedQuery.queryHash);\n if (!existingQuery) {\n newQueries.push(dehydratedQuery);\n } else {\n const hydrationIsNewer = dehydratedQuery.state.dataUpdatedAt > existingQuery.state.dataUpdatedAt;\n const queryAlreadyQueued = hydrationQueue?.find(query => query.queryHash === dehydratedQuery.queryHash);\n if (hydrationIsNewer && (!queryAlreadyQueued || dehydratedQuery.state.dataUpdatedAt > queryAlreadyQueued.state.dataUpdatedAt)) {\n existingQueries.push(dehydratedQuery);\n }\n }\n }\n if (newQueries.length > 0) {\n hydrate(client, {\n queries: newQueries\n }, optionsRef.current);\n }\n if (existingQueries.length > 0) {\n setHydrationQueue(prev => prev ? [...prev, ...existingQueries] : existingQueries);\n }\n }\n }, [client, hydrationQueue, state]);\n React.useEffect(() => {\n if (hydrationQueue) {\n hydrate(client, {\n queries: hydrationQueue\n }, optionsRef.current);\n setHydrationQueue(void 0);\n }\n }, [client, hydrationQueue]);\n return children;\n};\nexport { HydrationBoundary };","map":{"version":3,"names":["React","hydrate","useQueryClient","HydrationBoundary","children","options","state","queryClient","client","hydrationQueue","setHydrationQueue","useState","optionsRef","useRef","current","useMemo","queryCache","getQueryCache","queries","newQueries","existingQueries","dehydratedQuery","existingQuery","get","queryHash","push","hydrationIsNewer","dataUpdatedAt","queryAlreadyQueued","find","query","length","prev","useEffect"],"sources":["/Users/shoofle/Projects/the-forest/client/node_modules/@tanstack/react-query/src/HydrationBoundary.tsx"],"sourcesContent":["/* eslint-disable react-compiler/react-compiler */\n\n'use client'\nimport * as React from 'react'\n\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n DehydratedState,\n HydrateOptions,\n OmitKeyof,\n QueryClient,\n} from '@tanstack/query-core'\n\nexport interface HydrationBoundaryProps {\n state?: unknown\n options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {\n defaultOptions?: OmitKeyof<\n Exclude<HydrateOptions['defaultOptions'], undefined>,\n 'mutations'\n >\n }\n children?: React.ReactNode\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n const [hydrationQueue, setHydrationQueue] = React.useState<\n DehydratedState['queries'] | undefined\n >()\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // This useMemo is for performance reasons only, everything inside it _must_\n // be safe to run in every render and code here should be read as \"in render\".\n //\n // This code needs to happen during the render phase, because after initial\n // SSR, hydration needs to happen _before_ children render. Also, if hydrating\n // during a transition, we want to hydrate as much as is safe in render so\n // we can prerender as much as possible.\n //\n // For any