| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | "use client";
|
| 12 | import {
|
| 13 | deserializeErrors,
|
| 14 | getHydrationData
|
| 15 | } from "./chunk-K3SBCRK4.mjs";
|
| 16 | import {
|
| 17 | CRITICAL_CSS_DATA_ATTRIBUTE,
|
| 18 | FrameworkContext,
|
| 19 | RemixErrorBoundary,
|
| 20 | RouterProvider,
|
| 21 | createBrowserHistory,
|
| 22 | createClientRoutes,
|
| 23 | createClientRoutesWithHMRRevalidationOptOut,
|
| 24 | createRouter,
|
| 25 | decodeViaTurboStream,
|
| 26 | getPatchRoutesOnNavigationFunction,
|
| 27 | getTurboStreamSingleFetchDataStrategy,
|
| 28 | hydrationRouteProperties,
|
| 29 | invariant,
|
| 30 | mapRouteProperties,
|
| 31 | useFogOFWarDiscovery
|
| 32 | } from "./chunk-IZ57JD2V.mjs";
|
| 33 |
|
| 34 |
|
| 35 | import * as React from "react";
|
| 36 | import * as ReactDOM from "react-dom";
|
| 37 | function RouterProvider2(props) {
|
| 38 | return React.createElement(RouterProvider, { flushSync: ReactDOM.flushSync, ...props });
|
| 39 | }
|
| 40 |
|
| 41 |
|
| 42 | import * as React2 from "react";
|
| 43 | var ssrInfo = null;
|
| 44 | var router = null;
|
| 45 | function initSsrInfo() {
|
| 46 | if (!ssrInfo && window.__reactRouterContext && window.__reactRouterManifest && window.__reactRouterRouteModules) {
|
| 47 | if (window.__reactRouterManifest.sri === true) {
|
| 48 | const importMap = document.querySelector("script[rr-importmap]");
|
| 49 | if (importMap?.textContent) {
|
| 50 | try {
|
| 51 | window.__reactRouterManifest.sri = JSON.parse(
|
| 52 | importMap.textContent
|
| 53 | ).integrity;
|
| 54 | } catch (err) {
|
| 55 | console.error("Failed to parse import map", err);
|
| 56 | }
|
| 57 | }
|
| 58 | }
|
| 59 | ssrInfo = {
|
| 60 | context: window.__reactRouterContext,
|
| 61 | manifest: window.__reactRouterManifest,
|
| 62 | routeModules: window.__reactRouterRouteModules,
|
| 63 | stateDecodingPromise: void 0,
|
| 64 | router: void 0,
|
| 65 | routerInitialized: false
|
| 66 | };
|
| 67 | }
|
| 68 | }
|
| 69 | function createHydratedRouter({
|
| 70 | unstable_getContext
|
| 71 | }) {
|
| 72 | initSsrInfo();
|
| 73 | if (!ssrInfo) {
|
| 74 | throw new Error(
|
| 75 | "You must be using the SSR features of React Router in order to skip passing a `router` prop to `<RouterProvider>`"
|
| 76 | );
|
| 77 | }
|
| 78 | let localSsrInfo = ssrInfo;
|
| 79 | if (!ssrInfo.stateDecodingPromise) {
|
| 80 | let stream = ssrInfo.context.stream;
|
| 81 | invariant(stream, "No stream found for single fetch decoding");
|
| 82 | ssrInfo.context.stream = void 0;
|
| 83 | ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then((value) => {
|
| 84 | ssrInfo.context.state = value.value;
|
| 85 | localSsrInfo.stateDecodingPromise.value = true;
|
| 86 | }).catch((e) => {
|
| 87 | localSsrInfo.stateDecodingPromise.error = e;
|
| 88 | });
|
| 89 | }
|
| 90 | if (ssrInfo.stateDecodingPromise.error) {
|
| 91 | throw ssrInfo.stateDecodingPromise.error;
|
| 92 | }
|
| 93 | if (!ssrInfo.stateDecodingPromise.value) {
|
| 94 | throw ssrInfo.stateDecodingPromise;
|
| 95 | }
|
| 96 | let routes = createClientRoutes(
|
| 97 | ssrInfo.manifest.routes,
|
| 98 | ssrInfo.routeModules,
|
| 99 | ssrInfo.context.state,
|
| 100 | ssrInfo.context.ssr,
|
| 101 | ssrInfo.context.isSpaMode
|
| 102 | );
|
| 103 | let hydrationData = void 0;
|
| 104 | if (ssrInfo.context.isSpaMode) {
|
| 105 | let { loaderData } = ssrInfo.context.state;
|
| 106 | if (ssrInfo.manifest.routes.root?.hasLoader && loaderData && "root" in loaderData) {
|
| 107 | hydrationData = {
|
| 108 | loaderData: {
|
| 109 | root: loaderData.root
|
| 110 | }
|
| 111 | };
|
| 112 | }
|
| 113 | } else {
|
| 114 | hydrationData = getHydrationData(
|
| 115 | ssrInfo.context.state,
|
| 116 | routes,
|
| 117 | (routeId) => ({
|
| 118 | clientLoader: ssrInfo.routeModules[routeId]?.clientLoader,
|
| 119 | hasLoader: ssrInfo.manifest.routes[routeId]?.hasLoader === true,
|
| 120 | hasHydrateFallback: ssrInfo.routeModules[routeId]?.HydrateFallback != null
|
| 121 | }),
|
| 122 | window.location,
|
| 123 | window.__reactRouterContext?.basename,
|
| 124 | ssrInfo.context.isSpaMode
|
| 125 | );
|
| 126 | if (hydrationData && hydrationData.errors) {
|
| 127 | hydrationData.errors = deserializeErrors(hydrationData.errors);
|
| 128 | }
|
| 129 | }
|
| 130 | let router2 = createRouter({
|
| 131 | routes,
|
| 132 | history: createBrowserHistory(),
|
| 133 | basename: ssrInfo.context.basename,
|
| 134 | unstable_getContext,
|
| 135 | hydrationData,
|
| 136 | hydrationRouteProperties,
|
| 137 | mapRouteProperties,
|
| 138 | future: {
|
| 139 | unstable_middleware: ssrInfo.context.future.unstable_middleware
|
| 140 | },
|
| 141 | dataStrategy: getTurboStreamSingleFetchDataStrategy(
|
| 142 | () => router2,
|
| 143 | ssrInfo.manifest,
|
| 144 | ssrInfo.routeModules,
|
| 145 | ssrInfo.context.ssr,
|
| 146 | ssrInfo.context.basename
|
| 147 | ),
|
| 148 | patchRoutesOnNavigation: getPatchRoutesOnNavigationFunction(
|
| 149 | ssrInfo.manifest,
|
| 150 | ssrInfo.routeModules,
|
| 151 | ssrInfo.context.ssr,
|
| 152 | ssrInfo.context.routeDiscovery,
|
| 153 | ssrInfo.context.isSpaMode,
|
| 154 | ssrInfo.context.basename
|
| 155 | )
|
| 156 | });
|
| 157 | ssrInfo.router = router2;
|
| 158 | if (router2.state.initialized) {
|
| 159 | ssrInfo.routerInitialized = true;
|
| 160 | router2.initialize();
|
| 161 | }
|
| 162 | router2.createRoutesForHMR =
|
| 163 | createClientRoutesWithHMRRevalidationOptOut;
|
| 164 | window.__reactRouterDataRouter = router2;
|
| 165 | return router2;
|
| 166 | }
|
| 167 | function HydratedRouter(props) {
|
| 168 | if (!router) {
|
| 169 | router = createHydratedRouter({
|
| 170 | unstable_getContext: props.unstable_getContext
|
| 171 | });
|
| 172 | }
|
| 173 | let [criticalCss, setCriticalCss] = React2.useState(
|
| 174 | process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0
|
| 175 | );
|
| 176 | React2.useEffect(() => {
|
| 177 | if (process.env.NODE_ENV === "development") {
|
| 178 | setCriticalCss(void 0);
|
| 179 | }
|
| 180 | }, []);
|
| 181 | React2.useEffect(() => {
|
| 182 | if (process.env.NODE_ENV === "development" && criticalCss === void 0) {
|
| 183 | document.querySelectorAll(`[${CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
|
| 184 | }
|
| 185 | }, [criticalCss]);
|
| 186 | let [location, setLocation] = React2.useState(router.state.location);
|
| 187 | React2.useLayoutEffect(() => {
|
| 188 | if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
|
| 189 | ssrInfo.routerInitialized = true;
|
| 190 | ssrInfo.router.initialize();
|
| 191 | }
|
| 192 | }, []);
|
| 193 | React2.useLayoutEffect(() => {
|
| 194 | if (ssrInfo && ssrInfo.router) {
|
| 195 | return ssrInfo.router.subscribe((newState) => {
|
| 196 | if (newState.location !== location) {
|
| 197 | setLocation(newState.location);
|
| 198 | }
|
| 199 | });
|
| 200 | }
|
| 201 | }, [location]);
|
| 202 | invariant(ssrInfo, "ssrInfo unavailable for HydratedRouter");
|
| 203 | useFogOFWarDiscovery(
|
| 204 | router,
|
| 205 | ssrInfo.manifest,
|
| 206 | ssrInfo.routeModules,
|
| 207 | ssrInfo.context.ssr,
|
| 208 | ssrInfo.context.routeDiscovery,
|
| 209 | ssrInfo.context.isSpaMode
|
| 210 | );
|
| 211 | return (
|
| 212 |
|
| 213 |
|
| 214 | React2.createElement(React2.Fragment, null, React2.createElement(
|
| 215 | FrameworkContext.Provider,
|
| 216 | {
|
| 217 | value: {
|
| 218 | manifest: ssrInfo.manifest,
|
| 219 | routeModules: ssrInfo.routeModules,
|
| 220 | future: ssrInfo.context.future,
|
| 221 | criticalCss,
|
| 222 | ssr: ssrInfo.context.ssr,
|
| 223 | isSpaMode: ssrInfo.context.isSpaMode,
|
| 224 | routeDiscovery: ssrInfo.context.routeDiscovery
|
| 225 | }
|
| 226 | },
|
| 227 | React2.createElement(RemixErrorBoundary, { location }, React2.createElement(RouterProvider2, { router }))
|
| 228 | ), React2.createElement(React2.Fragment, null))
|
| 229 | );
|
| 230 | }
|
| 231 | export {
|
| 232 | HydratedRouter,
|
| 233 | RouterProvider2 as RouterProvider
|
| 234 | };
|