UNPKG

1.19 kBJavaScriptView Raw
1/**
2 * react-router v8.4.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 { createDataRouteMatcher } from "../../router/router.js";
12import { shouldHydrateRouteLoader } from "./routes.js";
13//#region lib/dom/ssr/hydration.tsx
14function getHydrationData({ state, routes, getRouteInfo, location, basename, future, isSpaMode }) {
15 let hydrationData = {
16 ...state,
17 loaderData: { ...state.loaderData }
18 };
19 let dataRouteMatcher = createDataRouteMatcher(future, basename || "/");
20 dataRouteMatcher.update(routes);
21 let initialMatches = dataRouteMatcher.match(location);
22 if (initialMatches) for (let match of initialMatches) {
23 let routeId = match.route.id;
24 let routeInfo = getRouteInfo(routeId);
25 if (shouldHydrateRouteLoader(routeId, routeInfo.clientLoader, routeInfo.hasLoader, isSpaMode) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) delete hydrationData.loaderData[routeId];
26 else if (!routeInfo.hasLoader) hydrationData.loaderData[routeId] = null;
27 }
28 return hydrationData;
29}
30//#endregion
31export { getHydrationData };