UNPKG

1.07 kBJavaScriptView Raw
1/**
2 * react-router v8.0.0
3 *
4 * Copyright (c) Remix Software Inc.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE.md file in the root directory of this source tree.
8 *
9 * @license MIT
10 */
11import { matchRoutes } from "../../router/utils.js";
12import { shouldHydrateRouteLoader } from "./routes.js";
13//#region lib/dom/ssr/hydration.tsx
14function getHydrationData({ state, routes, getRouteInfo, location, basename, isSpaMode }) {
15 let hydrationData = {
16 ...state,
17 loaderData: { ...state.loaderData }
18 };
19 let initialMatches = matchRoutes(routes, location, basename);
20 if (initialMatches) for (let match of initialMatches) {
21 let routeId = match.route.id;
22 let routeInfo = getRouteInfo(routeId);
23 if (shouldHydrateRouteLoader(routeId, routeInfo.clientLoader, routeInfo.hasLoader, isSpaMode) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) delete hydrationData.loaderData[routeId];
24 else if (!routeInfo.hasLoader) hydrationData.loaderData[routeId] = null;
25 }
26 return hydrationData;
27}
28//#endregion
29export { getHydrationData };