|
| 1 | +import { E as ErrorResponseImpl, r as reactExports, m as matchRoutes, c as createRouter, a as createBrowserHistory, b as mapRouteProperties, j as jsxRuntimeExports } from "./index-C3JligFb.js"; |
| 2 | +import { c as createClientRoutesWithHMRRevalidationOptOut, i as invariant, d as decodeViaTurboStream, a as createClientRoutes, s as shouldHydrateRouteLoader, b as initFogOfWar, g as getSingleFetchDataStrategy, u as useFogOFWarDiscovery, R as RemixContext, e as RemixErrorBoundary, f as RouterProvider, r as reactDomExports } from "./components-Dv2u7XfC.js"; |
| 3 | +/** |
| 4 | + * @remix-run/react v2.10.3 |
| 5 | + * |
| 6 | + * Copyright (c) Remix Software Inc. |
| 7 | + * |
| 8 | + * This source code is licensed under the MIT license found in the |
| 9 | + * LICENSE.md file in the root directory of this source tree. |
| 10 | + * |
| 11 | + * @license MIT |
| 12 | + */ |
| 13 | +function deserializeErrors(errors) { |
| 14 | + if (!errors) return null; |
| 15 | + let entries = Object.entries(errors); |
| 16 | + let serialized = {}; |
| 17 | + for (let [key, val] of entries) { |
| 18 | + if (val && val.__type === "RouteErrorResponse") { |
| 19 | + serialized[key] = new ErrorResponseImpl(val.status, val.statusText, val.data, val.internal === true); |
| 20 | + } else if (val && val.__type === "Error") { |
| 21 | + if (val.__subType) { |
| 22 | + let ErrorConstructor = window[val.__subType]; |
| 23 | + if (typeof ErrorConstructor === "function") { |
| 24 | + try { |
| 25 | + let error = new ErrorConstructor(val.message); |
| 26 | + error.stack = val.stack; |
| 27 | + serialized[key] = error; |
| 28 | + } catch (e) { |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + if (serialized[key] == null) { |
| 33 | + let error = new Error(val.message); |
| 34 | + error.stack = val.stack; |
| 35 | + serialized[key] = error; |
| 36 | + } |
| 37 | + } else { |
| 38 | + serialized[key] = val; |
| 39 | + } |
| 40 | + } |
| 41 | + return serialized; |
| 42 | +} |
| 43 | +/** |
| 44 | + * @remix-run/react v2.10.3 |
| 45 | + * |
| 46 | + * Copyright (c) Remix Software Inc. |
| 47 | + * |
| 48 | + * This source code is licensed under the MIT license found in the |
| 49 | + * LICENSE.md file in the root directory of this source tree. |
| 50 | + * |
| 51 | + * @license MIT |
| 52 | + */ |
| 53 | +let stateDecodingPromise; |
| 54 | +let router; |
| 55 | +let routerInitialized = false; |
| 56 | +let hmrAbortController; |
| 57 | +let hmrRouterReadyResolve; |
| 58 | +let hmrRouterReadyPromise = new Promise((resolve) => { |
| 59 | + hmrRouterReadyResolve = resolve; |
| 60 | +}).catch(() => { |
| 61 | + return void 0; |
| 62 | +}); |
| 63 | +if (import.meta && void 0) { |
| 64 | + (void 0).accept("remix:manifest", async ({ |
| 65 | + assetsManifest, |
| 66 | + needsRevalidation |
| 67 | + }) => { |
| 68 | + let router2 = await hmrRouterReadyPromise; |
| 69 | + if (!router2) { |
| 70 | + console.error("Failed to accept HMR update because the router was not ready."); |
| 71 | + return; |
| 72 | + } |
| 73 | + let routeIds = [...new Set(router2.state.matches.map((m2) => m2.route.id).concat(Object.keys(window.__remixRouteModules)))]; |
| 74 | + if (hmrAbortController) { |
| 75 | + hmrAbortController.abort(); |
| 76 | + } |
| 77 | + hmrAbortController = new AbortController(); |
| 78 | + let signal = hmrAbortController.signal; |
| 79 | + let newRouteModules = Object.assign({}, window.__remixRouteModules, Object.fromEntries((await Promise.all(routeIds.map(async (id) => { |
| 80 | + var _assetsManifest$hmr, _window$__remixRouteM, _window$__remixRouteM2, _window$__remixRouteM3; |
| 81 | + if (!assetsManifest.routes[id]) { |
| 82 | + return null; |
| 83 | + } |
| 84 | + let imported = await import(assetsManifest.routes[id].module + `?t=${(_assetsManifest$hmr = assetsManifest.hmr) === null || _assetsManifest$hmr === void 0 ? void 0 : _assetsManifest$hmr.timestamp}`); |
| 85 | + return [id, { |
| 86 | + ...imported, |
| 87 | + // react-refresh takes care of updating these in-place, |
| 88 | + // if we don't preserve existing values we'll loose state. |
| 89 | + default: imported.default ? ((_window$__remixRouteM = window.__remixRouteModules[id]) === null || _window$__remixRouteM === void 0 ? void 0 : _window$__remixRouteM.default) ?? imported.default : imported.default, |
| 90 | + ErrorBoundary: imported.ErrorBoundary ? ((_window$__remixRouteM2 = window.__remixRouteModules[id]) === null || _window$__remixRouteM2 === void 0 ? void 0 : _window$__remixRouteM2.ErrorBoundary) ?? imported.ErrorBoundary : imported.ErrorBoundary, |
| 91 | + HydrateFallback: imported.HydrateFallback ? ((_window$__remixRouteM3 = window.__remixRouteModules[id]) === null || _window$__remixRouteM3 === void 0 ? void 0 : _window$__remixRouteM3.HydrateFallback) ?? imported.HydrateFallback : imported.HydrateFallback |
| 92 | + }]; |
| 93 | + }))).filter(Boolean))); |
| 94 | + Object.assign(window.__remixRouteModules, newRouteModules); |
| 95 | + let routes = createClientRoutesWithHMRRevalidationOptOut(needsRevalidation, assetsManifest.routes, window.__remixRouteModules, window.__remixContext.state, window.__remixContext.future, window.__remixContext.isSpaMode); |
| 96 | + router2._internalSetRoutes(routes); |
| 97 | + let unsub = router2.subscribe((state) => { |
| 98 | + if (state.revalidation === "idle") { |
| 99 | + unsub(); |
| 100 | + if (signal.aborted) return; |
| 101 | + setTimeout(() => { |
| 102 | + Object.assign(window.__remixManifest, assetsManifest); |
| 103 | + window.$RefreshRuntime$.performReactRefresh(); |
| 104 | + }, 1); |
| 105 | + } |
| 106 | + }); |
| 107 | + window.__remixRevalidation = (window.__remixRevalidation || 0) + 1; |
| 108 | + router2.revalidate(); |
| 109 | + }); |
| 110 | +} |
| 111 | +function RemixBrowser(_props) { |
| 112 | + if (!router) { |
| 113 | + let initialPathname = window.__remixContext.url; |
| 114 | + let hydratedPathname = window.location.pathname; |
| 115 | + if (initialPathname !== hydratedPathname && !window.__remixContext.isSpaMode) { |
| 116 | + let errorMsg = `Initial URL (${initialPathname}) does not match URL at time of hydration (${hydratedPathname}), reloading page...`; |
| 117 | + console.error(errorMsg); |
| 118 | + window.location.reload(); |
| 119 | + return /* @__PURE__ */ reactExports.createElement(reactExports.Fragment, null); |
| 120 | + } |
| 121 | + if (window.__remixContext.future.unstable_singleFetch) { |
| 122 | + if (!stateDecodingPromise) { |
| 123 | + let stream = window.__remixContext.stream; |
| 124 | + invariant(stream, "No stream found for single fetch decoding"); |
| 125 | + window.__remixContext.stream = void 0; |
| 126 | + stateDecodingPromise = decodeViaTurboStream(stream, window).then((value) => { |
| 127 | + window.__remixContext.state = value.value; |
| 128 | + stateDecodingPromise.value = true; |
| 129 | + }).catch((e) => { |
| 130 | + stateDecodingPromise.error = e; |
| 131 | + }); |
| 132 | + } |
| 133 | + if (stateDecodingPromise.error) { |
| 134 | + throw stateDecodingPromise.error; |
| 135 | + } |
| 136 | + if (!stateDecodingPromise.value) { |
| 137 | + throw stateDecodingPromise; |
| 138 | + } |
| 139 | + } |
| 140 | + let routes = createClientRoutes(window.__remixManifest.routes, window.__remixRouteModules, window.__remixContext.state, window.__remixContext.future, window.__remixContext.isSpaMode); |
| 141 | + let hydrationData = void 0; |
| 142 | + if (!window.__remixContext.isSpaMode) { |
| 143 | + hydrationData = { |
| 144 | + ...window.__remixContext.state, |
| 145 | + loaderData: { |
| 146 | + ...window.__remixContext.state.loaderData |
| 147 | + } |
| 148 | + }; |
| 149 | + let initialMatches = matchRoutes(routes, window.location, window.__remixContext.basename); |
| 150 | + if (initialMatches) { |
| 151 | + for (let match of initialMatches) { |
| 152 | + let routeId = match.route.id; |
| 153 | + let route = window.__remixRouteModules[routeId]; |
| 154 | + let manifestRoute = window.__remixManifest.routes[routeId]; |
| 155 | + if (route && shouldHydrateRouteLoader(manifestRoute, route, window.__remixContext.isSpaMode) && (route.HydrateFallback || !manifestRoute.hasLoader)) { |
| 156 | + hydrationData.loaderData[routeId] = void 0; |
| 157 | + } else if (manifestRoute && !manifestRoute.hasLoader) { |
| 158 | + hydrationData.loaderData[routeId] = null; |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + if (hydrationData && hydrationData.errors) { |
| 163 | + hydrationData.errors = deserializeErrors(hydrationData.errors); |
| 164 | + } |
| 165 | + } |
| 166 | + let { |
| 167 | + enabled: isFogOfWarEnabled, |
| 168 | + patchRoutesOnMiss |
| 169 | + } = initFogOfWar(window.__remixManifest, window.__remixRouteModules, window.__remixContext.future, window.__remixContext.isSpaMode, window.__remixContext.basename); |
| 170 | + router = createRouter({ |
| 171 | + routes, |
| 172 | + history: createBrowserHistory(), |
| 173 | + basename: window.__remixContext.basename, |
| 174 | + future: { |
| 175 | + v7_normalizeFormMethod: true, |
| 176 | + v7_fetcherPersist: window.__remixContext.future.v3_fetcherPersist, |
| 177 | + v7_partialHydration: true, |
| 178 | + v7_prependBasename: true, |
| 179 | + v7_relativeSplatPath: window.__remixContext.future.v3_relativeSplatPath, |
| 180 | + // Single fetch enables this underlying behavior |
| 181 | + v7_skipActionErrorRevalidation: window.__remixContext.future.unstable_singleFetch === true |
| 182 | + }, |
| 183 | + hydrationData, |
| 184 | + mapRouteProperties, |
| 185 | + unstable_dataStrategy: window.__remixContext.future.unstable_singleFetch ? getSingleFetchDataStrategy(window.__remixManifest, window.__remixRouteModules) : void 0, |
| 186 | + ...isFogOfWarEnabled ? { |
| 187 | + unstable_patchRoutesOnMiss: patchRoutesOnMiss |
| 188 | + } : {} |
| 189 | + }); |
| 190 | + if (router.state.initialized) { |
| 191 | + routerInitialized = true; |
| 192 | + router.initialize(); |
| 193 | + } |
| 194 | + router.createRoutesForHMR = createClientRoutesWithHMRRevalidationOptOut; |
| 195 | + window.__remixRouter = router; |
| 196 | + if (hmrRouterReadyResolve) { |
| 197 | + hmrRouterReadyResolve(router); |
| 198 | + } |
| 199 | + } |
| 200 | + let [criticalCss, setCriticalCss] = reactExports.useState(void 0); |
| 201 | + let [location, setLocation] = reactExports.useState(router.state.location); |
| 202 | + reactExports.useLayoutEffect(() => { |
| 203 | + if (!routerInitialized) { |
| 204 | + routerInitialized = true; |
| 205 | + router.initialize(); |
| 206 | + } |
| 207 | + }, []); |
| 208 | + reactExports.useLayoutEffect(() => { |
| 209 | + return router.subscribe((newState) => { |
| 210 | + if (newState.location !== location) { |
| 211 | + setLocation(newState.location); |
| 212 | + } |
| 213 | + }); |
| 214 | + }, [location]); |
| 215 | + useFogOFWarDiscovery(router, window.__remixManifest, window.__remixRouteModules, window.__remixContext.future, window.__remixContext.isSpaMode); |
| 216 | + return ( |
| 217 | + // This fragment is important to ensure we match the <RemixServer> JSX |
| 218 | + // structure so that useId values hydrate correctly |
| 219 | + /* @__PURE__ */ reactExports.createElement(reactExports.Fragment, null, /* @__PURE__ */ reactExports.createElement(RemixContext.Provider, { |
| 220 | + value: { |
| 221 | + manifest: window.__remixManifest, |
| 222 | + routeModules: window.__remixRouteModules, |
| 223 | + future: window.__remixContext.future, |
| 224 | + criticalCss, |
| 225 | + isSpaMode: window.__remixContext.isSpaMode |
| 226 | + } |
| 227 | + }, /* @__PURE__ */ reactExports.createElement(RemixErrorBoundary, { |
| 228 | + location |
| 229 | + }, /* @__PURE__ */ reactExports.createElement(RouterProvider, { |
| 230 | + router, |
| 231 | + fallbackElement: null, |
| 232 | + future: { |
| 233 | + v7_startTransition: true |
| 234 | + } |
| 235 | + }))), window.__remixContext.future.unstable_singleFetch ? /* @__PURE__ */ reactExports.createElement(reactExports.Fragment, null) : null) |
| 236 | + ); |
| 237 | +} |
| 238 | +var hydrateRoot; |
| 239 | +var m = reactDomExports; |
| 240 | +{ |
| 241 | + m.createRoot; |
| 242 | + hydrateRoot = m.hydrateRoot; |
| 243 | +} |
| 244 | +reactExports.startTransition(() => { |
| 245 | + hydrateRoot( |
| 246 | + document, |
| 247 | + /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.StrictMode, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(RemixBrowser, {}) }) |
| 248 | + ); |
| 249 | +}); |
0 commit comments