| 1 | "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | "use client";
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 | var _chunkKSEWV2VOjs = require('./chunk-KSEWV2VO.js');
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 | var _chunkXOLAXE2Zjs = require('./chunk-XOLAXE2Z.js');
|
| 36 |
|
| 37 |
|
| 38 | var _react = require('react'); var React = _interopRequireWildcard(_react); var React2 = _interopRequireWildcard(_react); var React3 = _interopRequireWildcard(_react);
|
| 39 | var _reactdom = require('react-dom'); var ReactDOM = _interopRequireWildcard(_reactdom); var ReactDOM2 = _interopRequireWildcard(_reactdom);
|
| 40 | var _reactrouter = require('react-router');
|
| 41 | function RouterProvider2(props) {
|
| 42 | return React.createElement(_reactrouter.RouterProvider, { flushSync: ReactDOM.flushSync, ...props });
|
| 43 | }
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 | var ssrInfo = null;
|
| 65 | var router = null;
|
| 66 | function initSsrInfo() {
|
| 67 | if (!ssrInfo && window.__reactRouterContext && window.__reactRouterManifest && window.__reactRouterRouteModules) {
|
| 68 | if (window.__reactRouterManifest.sri === true) {
|
| 69 | const importMap = document.querySelector("script[rr-importmap]");
|
| 70 | if (_optionalChain([importMap, 'optionalAccess', _2 => _2.textContent])) {
|
| 71 | try {
|
| 72 | window.__reactRouterManifest.sri = JSON.parse(
|
| 73 | importMap.textContent
|
| 74 | ).integrity;
|
| 75 | } catch (err) {
|
| 76 | console.error("Failed to parse import map", err);
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 | ssrInfo = {
|
| 81 | context: window.__reactRouterContext,
|
| 82 | manifest: window.__reactRouterManifest,
|
| 83 | routeModules: window.__reactRouterRouteModules,
|
| 84 | stateDecodingPromise: void 0,
|
| 85 | router: void 0,
|
| 86 | routerInitialized: false
|
| 87 | };
|
| 88 | }
|
| 89 | }
|
| 90 | function createHydratedRouter({
|
| 91 | getContext,
|
| 92 | unstable_instrumentations
|
| 93 | }) {
|
| 94 | initSsrInfo();
|
| 95 | if (!ssrInfo) {
|
| 96 | throw new Error(
|
| 97 | "You must be using the SSR features of React Router in order to skip passing a `router` prop to `<RouterProvider>`"
|
| 98 | );
|
| 99 | }
|
| 100 | let localSsrInfo = ssrInfo;
|
| 101 | if (!ssrInfo.stateDecodingPromise) {
|
| 102 | let stream = ssrInfo.context.stream;
|
| 103 | _reactrouter.UNSAFE_invariant.call(void 0, stream, "No stream found for single fetch decoding");
|
| 104 | ssrInfo.context.stream = void 0;
|
| 105 | ssrInfo.stateDecodingPromise = _reactrouter.UNSAFE_decodeViaTurboStream.call(void 0, stream, window).then((value) => {
|
| 106 | ssrInfo.context.state = value.value;
|
| 107 | localSsrInfo.stateDecodingPromise.value = true;
|
| 108 | }).catch((e) => {
|
| 109 | localSsrInfo.stateDecodingPromise.error = e;
|
| 110 | });
|
| 111 | }
|
| 112 | if (ssrInfo.stateDecodingPromise.error) {
|
| 113 | throw ssrInfo.stateDecodingPromise.error;
|
| 114 | }
|
| 115 | if (!ssrInfo.stateDecodingPromise.value) {
|
| 116 | throw ssrInfo.stateDecodingPromise;
|
| 117 | }
|
| 118 | let routes = _reactrouter.UNSAFE_createClientRoutes.call(void 0,
|
| 119 | ssrInfo.manifest.routes,
|
| 120 | ssrInfo.routeModules,
|
| 121 | ssrInfo.context.state,
|
| 122 | ssrInfo.context.ssr,
|
| 123 | ssrInfo.context.isSpaMode
|
| 124 | );
|
| 125 | let hydrationData = void 0;
|
| 126 | if (ssrInfo.context.isSpaMode) {
|
| 127 | let { loaderData } = ssrInfo.context.state;
|
| 128 | if (_optionalChain([ssrInfo, 'access', _3 => _3.manifest, 'access', _4 => _4.routes, 'access', _5 => _5.root, 'optionalAccess', _6 => _6.hasLoader]) && loaderData && "root" in loaderData) {
|
| 129 | hydrationData = {
|
| 130 | loaderData: {
|
| 131 | root: loaderData.root
|
| 132 | }
|
| 133 | };
|
| 134 | }
|
| 135 | } else {
|
| 136 | hydrationData = _reactrouter.UNSAFE_getHydrationData.call(void 0, {
|
| 137 | state: ssrInfo.context.state,
|
| 138 | routes,
|
| 139 | getRouteInfo: (routeId) => ({
|
| 140 | clientLoader: _optionalChain([ssrInfo, 'access', _7 => _7.routeModules, 'access', _8 => _8[routeId], 'optionalAccess', _9 => _9.clientLoader]),
|
| 141 | hasLoader: _optionalChain([ssrInfo, 'access', _10 => _10.manifest, 'access', _11 => _11.routes, 'access', _12 => _12[routeId], 'optionalAccess', _13 => _13.hasLoader]) === true,
|
| 142 | hasHydrateFallback: _optionalChain([ssrInfo, 'access', _14 => _14.routeModules, 'access', _15 => _15[routeId], 'optionalAccess', _16 => _16.HydrateFallback]) != null
|
| 143 | }),
|
| 144 | location: window.location,
|
| 145 | basename: _optionalChain([window, 'access', _17 => _17.__reactRouterContext, 'optionalAccess', _18 => _18.basename]),
|
| 146 | isSpaMode: ssrInfo.context.isSpaMode
|
| 147 | });
|
| 148 | if (hydrationData && hydrationData.errors) {
|
| 149 | hydrationData.errors = _reactrouter.UNSAFE_deserializeErrors.call(void 0, hydrationData.errors);
|
| 150 | }
|
| 151 | }
|
| 152 | if (window.history.state && window.history.state.masked) {
|
| 153 | window.history.replaceState(
|
| 154 | { ...window.history.state, masked: void 0 },
|
| 155 | ""
|
| 156 | );
|
| 157 | }
|
| 158 | let router2 = _reactrouter.UNSAFE_createRouter.call(void 0, {
|
| 159 | routes,
|
| 160 | history: _reactrouter.UNSAFE_createBrowserHistory.call(void 0, ),
|
| 161 | basename: ssrInfo.context.basename,
|
| 162 | getContext,
|
| 163 | hydrationData,
|
| 164 | hydrationRouteProperties: _reactrouter.UNSAFE_hydrationRouteProperties,
|
| 165 | unstable_instrumentations,
|
| 166 | mapRouteProperties: _reactrouter.UNSAFE_mapRouteProperties,
|
| 167 | future: {
|
| 168 | middleware: ssrInfo.context.future.v8_middleware
|
| 169 | },
|
| 170 | dataStrategy: _reactrouter.UNSAFE_getTurboStreamSingleFetchDataStrategy.call(void 0,
|
| 171 | () => router2,
|
| 172 | ssrInfo.manifest,
|
| 173 | ssrInfo.routeModules,
|
| 174 | ssrInfo.context.ssr,
|
| 175 | ssrInfo.context.basename,
|
| 176 | ssrInfo.context.future.unstable_trailingSlashAwareDataRequests
|
| 177 | ),
|
| 178 | patchRoutesOnNavigation: _reactrouter.UNSAFE_getPatchRoutesOnNavigationFunction.call(void 0,
|
| 179 | () => router2,
|
| 180 | ssrInfo.manifest,
|
| 181 | ssrInfo.routeModules,
|
| 182 | ssrInfo.context.ssr,
|
| 183 | ssrInfo.context.routeDiscovery,
|
| 184 | ssrInfo.context.isSpaMode,
|
| 185 | ssrInfo.context.basename
|
| 186 | )
|
| 187 | });
|
| 188 | ssrInfo.router = router2;
|
| 189 | if (router2.state.initialized) {
|
| 190 | ssrInfo.routerInitialized = true;
|
| 191 | router2.initialize();
|
| 192 | }
|
| 193 | router2.createRoutesForHMR =
|
| 194 | _reactrouter.UNSAFE_createClientRoutesWithHMRRevalidationOptOut;
|
| 195 | window.__reactRouterDataRouter = router2;
|
| 196 | return router2;
|
| 197 | }
|
| 198 | function HydratedRouter(props) {
|
| 199 | if (!router) {
|
| 200 | router = createHydratedRouter({
|
| 201 | getContext: props.getContext,
|
| 202 | unstable_instrumentations: props.unstable_instrumentations
|
| 203 | });
|
| 204 | }
|
| 205 | let [criticalCss, setCriticalCss] = React2.useState(
|
| 206 | process.env.NODE_ENV === "development" ? _optionalChain([ssrInfo, 'optionalAccess', _19 => _19.context, 'access', _20 => _20.criticalCss]) : void 0
|
| 207 | );
|
| 208 | React2.useEffect(() => {
|
| 209 | if (process.env.NODE_ENV === "development") {
|
| 210 | setCriticalCss(void 0);
|
| 211 | }
|
| 212 | }, []);
|
| 213 | React2.useEffect(() => {
|
| 214 | if (process.env.NODE_ENV === "development" && criticalCss === void 0) {
|
| 215 | document.querySelectorAll(`[${_chunkXOLAXE2Zjs.CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
|
| 216 | }
|
| 217 | }, [criticalCss]);
|
| 218 | let [location2, setLocation] = React2.useState(router.state.location);
|
| 219 | React2.useLayoutEffect(() => {
|
| 220 | if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
|
| 221 | ssrInfo.routerInitialized = true;
|
| 222 | ssrInfo.router.initialize();
|
| 223 | }
|
| 224 | }, []);
|
| 225 | React2.useLayoutEffect(() => {
|
| 226 | if (ssrInfo && ssrInfo.router) {
|
| 227 | return ssrInfo.router.subscribe((newState) => {
|
| 228 | if (newState.location !== location2) {
|
| 229 | setLocation(newState.location);
|
| 230 | }
|
| 231 | });
|
| 232 | }
|
| 233 | }, [location2]);
|
| 234 | _reactrouter.UNSAFE_invariant.call(void 0, ssrInfo, "ssrInfo unavailable for HydratedRouter");
|
| 235 | _reactrouter.UNSAFE_useFogOFWarDiscovery.call(void 0,
|
| 236 | router,
|
| 237 | ssrInfo.manifest,
|
| 238 | ssrInfo.routeModules,
|
| 239 | ssrInfo.context.ssr,
|
| 240 | ssrInfo.context.routeDiscovery,
|
| 241 | ssrInfo.context.isSpaMode
|
| 242 | );
|
| 243 | return (
|
| 244 |
|
| 245 |
|
| 246 | React2.createElement(React2.Fragment, null, React2.createElement(
|
| 247 | _reactrouter.UNSAFE_FrameworkContext.Provider,
|
| 248 | {
|
| 249 | value: {
|
| 250 | manifest: ssrInfo.manifest,
|
| 251 | routeModules: ssrInfo.routeModules,
|
| 252 | future: ssrInfo.context.future,
|
| 253 | criticalCss,
|
| 254 | ssr: ssrInfo.context.ssr,
|
| 255 | isSpaMode: ssrInfo.context.isSpaMode,
|
| 256 | routeDiscovery: ssrInfo.context.routeDiscovery
|
| 257 | }
|
| 258 | },
|
| 259 | React2.createElement(_reactrouter.UNSAFE_RemixErrorBoundary, { location: location2 }, React2.createElement(
|
| 260 | RouterProvider2,
|
| 261 | {
|
| 262 | router,
|
| 263 | unstable_useTransitions: props.unstable_useTransitions,
|
| 264 | onError: props.onError
|
| 265 | }
|
| 266 | ))
|
| 267 | ), React2.createElement(React2.Fragment, null))
|
| 268 | );
|
| 269 | }
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 | function createCallServer({
|
| 275 | createFromReadableStream,
|
| 276 | createTemporaryReferenceSet,
|
| 277 | encodeReply,
|
| 278 | fetch: fetchImplementation = fetch
|
| 279 | }) {
|
| 280 | const globalVar = window;
|
| 281 | let landedActionId = 0;
|
| 282 | return async (id, args) => {
|
| 283 | let actionId = globalVar.__routerActionID = (_nullishCoalesce(globalVar.__routerActionID, () => ( (globalVar.__routerActionID = 0)))) + 1;
|
| 284 | const temporaryReferences = createTemporaryReferenceSet();
|
| 285 | const payloadPromise = fetchImplementation(
|
| 286 | new Request(location.href, {
|
| 287 | body: await encodeReply(args, { temporaryReferences }),
|
| 288 | method: "POST",
|
| 289 | headers: {
|
| 290 | Accept: "text/x-component",
|
| 291 | "rsc-action-id": id
|
| 292 | }
|
| 293 | })
|
| 294 | ).then((response) => {
|
| 295 | if (!response.body) {
|
| 296 | throw new Error("No response body");
|
| 297 | }
|
| 298 | return createFromReadableStream(response.body, {
|
| 299 | temporaryReferences
|
| 300 | });
|
| 301 | });
|
| 302 | React3.startTransition(
|
| 303 | () => (
|
| 304 |
|
| 305 | Promise.resolve(payloadPromise).then(async (payload) => {
|
| 306 | if (payload.type === "redirect") {
|
| 307 | if (payload.reload || isExternalLocation(payload.location)) {
|
| 308 | window.location.href = payload.location;
|
| 309 | return;
|
| 310 | }
|
| 311 | React3.startTransition(() => {
|
| 312 | globalVar.__reactRouterDataRouter.navigate(payload.location, {
|
| 313 | replace: payload.replace
|
| 314 | });
|
| 315 | });
|
| 316 | return;
|
| 317 | }
|
| 318 | if (payload.type !== "action") {
|
| 319 | throw new Error("Unexpected payload type");
|
| 320 | }
|
| 321 | const rerender = await payload.rerender;
|
| 322 | if (rerender && landedActionId < actionId && globalVar.__routerActionID <= actionId) {
|
| 323 | if (rerender.type === "redirect") {
|
| 324 | if (rerender.reload || isExternalLocation(rerender.location)) {
|
| 325 | window.location.href = rerender.location;
|
| 326 | return;
|
| 327 | }
|
| 328 | React3.startTransition(() => {
|
| 329 | globalVar.__reactRouterDataRouter.navigate(rerender.location, {
|
| 330 | replace: rerender.replace
|
| 331 | });
|
| 332 | });
|
| 333 | return;
|
| 334 | }
|
| 335 | React3.startTransition(() => {
|
| 336 | let lastMatch;
|
| 337 | for (const match of rerender.matches) {
|
| 338 | globalVar.__reactRouterDataRouter.patchRoutes(
|
| 339 | _nullishCoalesce(_optionalChain([lastMatch, 'optionalAccess', _21 => _21.id]), () => ( null)),
|
| 340 | [createRouteFromServerManifest(match)],
|
| 341 | true
|
| 342 | );
|
| 343 | lastMatch = match;
|
| 344 | }
|
| 345 | window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp(
|
| 346 | {
|
| 347 | loaderData: Object.assign(
|
| 348 | {},
|
| 349 | globalVar.__reactRouterDataRouter.state.loaderData,
|
| 350 | rerender.loaderData
|
| 351 | ),
|
| 352 | errors: rerender.errors ? Object.assign(
|
| 353 | {},
|
| 354 | globalVar.__reactRouterDataRouter.state.errors,
|
| 355 | rerender.errors
|
| 356 | ) : null
|
| 357 | }
|
| 358 | );
|
| 359 | });
|
| 360 | }
|
| 361 | }).catch(() => {
|
| 362 | })
|
| 363 | )
|
| 364 | );
|
| 365 | return payloadPromise.then((payload) => {
|
| 366 | if (payload.type !== "action" && payload.type !== "redirect") {
|
| 367 | throw new Error("Unexpected payload type");
|
| 368 | }
|
| 369 | return payload.actionResult;
|
| 370 | });
|
| 371 | };
|
| 372 | }
|
| 373 | function createRouterFromPayload({
|
| 374 | fetchImplementation,
|
| 375 | createFromReadableStream,
|
| 376 | getContext,
|
| 377 | payload
|
| 378 | }) {
|
| 379 | const globalVar = window;
|
| 380 | if (globalVar.__reactRouterDataRouter && globalVar.__reactRouterRouteModules)
|
| 381 | return {
|
| 382 | router: globalVar.__reactRouterDataRouter,
|
| 383 | routeModules: globalVar.__reactRouterRouteModules
|
| 384 | };
|
| 385 | if (payload.type !== "render") throw new Error("Invalid payload type");
|
| 386 | globalVar.__reactRouterRouteModules = _nullishCoalesce(globalVar.__reactRouterRouteModules, () => ( {}));
|
| 387 | _chunkKSEWV2VOjs.populateRSCRouteModules.call(void 0, globalVar.__reactRouterRouteModules, payload.matches);
|
| 388 | let patches = new Map();
|
| 389 | _optionalChain([payload, 'access', _22 => _22.patches, 'optionalAccess', _23 => _23.forEach, 'call', _24 => _24((patch) => {
|
| 390 | _chunkXOLAXE2Zjs.invariant.call(void 0, patch.parentId, "Invalid patch parentId");
|
| 391 | if (!patches.has(patch.parentId)) {
|
| 392 | patches.set(patch.parentId, []);
|
| 393 | }
|
| 394 | _optionalChain([patches, 'access', _25 => _25.get, 'call', _26 => _26(patch.parentId), 'optionalAccess', _27 => _27.push, 'call', _28 => _28(patch)]);
|
| 395 | })]);
|
| 396 | let routes = payload.matches.reduceRight((previous, match) => {
|
| 397 | const route = createRouteFromServerManifest(
|
| 398 | match,
|
| 399 | payload
|
| 400 | );
|
| 401 | if (previous.length > 0) {
|
| 402 | route.children = previous;
|
| 403 | let childrenToPatch = patches.get(match.id);
|
| 404 | if (childrenToPatch) {
|
| 405 | route.children.push(
|
| 406 | ...childrenToPatch.map((r) => createRouteFromServerManifest(r))
|
| 407 | );
|
| 408 | }
|
| 409 | }
|
| 410 | return [route];
|
| 411 | }, []);
|
| 412 | globalVar.__reactRouterDataRouter = _chunkXOLAXE2Zjs.createRouter.call(void 0, {
|
| 413 | routes,
|
| 414 | getContext,
|
| 415 | basename: payload.basename,
|
| 416 | history: _chunkXOLAXE2Zjs.createBrowserHistory.call(void 0, ),
|
| 417 | hydrationData: _chunkKSEWV2VOjs.getHydrationData.call(void 0, {
|
| 418 | state: {
|
| 419 | loaderData: payload.loaderData,
|
| 420 | actionData: payload.actionData,
|
| 421 | errors: payload.errors
|
| 422 | },
|
| 423 | routes,
|
| 424 | getRouteInfo: (routeId) => {
|
| 425 | let match = payload.matches.find((m) => m.id === routeId);
|
| 426 | _chunkXOLAXE2Zjs.invariant.call(void 0, match, "Route not found in payload");
|
| 427 | return {
|
| 428 | clientLoader: match.clientLoader,
|
| 429 | hasLoader: match.hasLoader,
|
| 430 | hasHydrateFallback: match.hydrateFallbackElement != null
|
| 431 | };
|
| 432 | },
|
| 433 | location: payload.location,
|
| 434 | basename: payload.basename,
|
| 435 | isSpaMode: false
|
| 436 | }),
|
| 437 | async patchRoutesOnNavigation({ path, signal }) {
|
| 438 | if (discoveredPaths.has(path)) {
|
| 439 | return;
|
| 440 | }
|
| 441 | await fetchAndApplyManifestPatches(
|
| 442 | [path],
|
| 443 | createFromReadableStream,
|
| 444 | fetchImplementation,
|
| 445 | signal
|
| 446 | );
|
| 447 | },
|
| 448 |
|
| 449 | dataStrategy: getRSCSingleFetchDataStrategy(
|
| 450 | () => globalVar.__reactRouterDataRouter,
|
| 451 | true,
|
| 452 | payload.basename,
|
| 453 | createFromReadableStream,
|
| 454 | fetchImplementation
|
| 455 | )
|
| 456 | });
|
| 457 | if (globalVar.__reactRouterDataRouter.state.initialized) {
|
| 458 | globalVar.__routerInitialized = true;
|
| 459 | globalVar.__reactRouterDataRouter.initialize();
|
| 460 | } else {
|
| 461 | globalVar.__routerInitialized = false;
|
| 462 | }
|
| 463 | let lastLoaderData = void 0;
|
| 464 | globalVar.__reactRouterDataRouter.subscribe(({ loaderData, actionData }) => {
|
| 465 | if (lastLoaderData !== loaderData) {
|
| 466 | globalVar.__routerActionID = (_nullishCoalesce(globalVar.__routerActionID, () => ( (globalVar.__routerActionID = 0)))) + 1;
|
| 467 | }
|
| 468 | });
|
| 469 | globalVar.__reactRouterDataRouter._updateRoutesForHMR = (routeUpdateByRouteId) => {
|
| 470 | const oldRoutes = window.__reactRouterDataRouter.routes;
|
| 471 | const newRoutes = [];
|
| 472 | function walkRoutes(routes2, parentId) {
|
| 473 | return routes2.map((route) => {
|
| 474 | const routeUpdate = routeUpdateByRouteId.get(route.id);
|
| 475 | if (routeUpdate) {
|
| 476 | const {
|
| 477 | routeModule,
|
| 478 | hasAction,
|
| 479 | hasComponent,
|
| 480 | hasErrorBoundary,
|
| 481 | hasLoader
|
| 482 | } = routeUpdate;
|
| 483 | const newRoute = createRouteFromServerManifest({
|
| 484 | clientAction: routeModule.clientAction,
|
| 485 | clientLoader: routeModule.clientLoader,
|
| 486 | element: route.element,
|
| 487 | errorElement: route.errorElement,
|
| 488 | handle: route.handle,
|
| 489 | hasAction,
|
| 490 | hasComponent,
|
| 491 | hasErrorBoundary,
|
| 492 | hasLoader,
|
| 493 | hydrateFallbackElement: route.hydrateFallbackElement,
|
| 494 | id: route.id,
|
| 495 | index: route.index,
|
| 496 | links: routeModule.links,
|
| 497 | meta: routeModule.meta,
|
| 498 | parentId,
|
| 499 | path: route.path,
|
| 500 | shouldRevalidate: routeModule.shouldRevalidate
|
| 501 | });
|
| 502 | if (route.children) {
|
| 503 | newRoute.children = walkRoutes(route.children, route.id);
|
| 504 | }
|
| 505 | return newRoute;
|
| 506 | }
|
| 507 | const updatedRoute = { ...route };
|
| 508 | if (route.children) {
|
| 509 | updatedRoute.children = walkRoutes(route.children, route.id);
|
| 510 | }
|
| 511 | return updatedRoute;
|
| 512 | });
|
| 513 | }
|
| 514 | newRoutes.push(
|
| 515 | ...walkRoutes(oldRoutes, void 0)
|
| 516 | );
|
| 517 | window.__reactRouterDataRouter._internalSetRoutes(newRoutes);
|
| 518 | };
|
| 519 | return {
|
| 520 | router: globalVar.__reactRouterDataRouter,
|
| 521 | routeModules: globalVar.__reactRouterRouteModules
|
| 522 | };
|
| 523 | }
|
| 524 | var renderedRoutesContext = _chunkXOLAXE2Zjs.createContext.call(void 0, );
|
| 525 | function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReadableStream, fetchImplementation) {
|
| 526 | let dataStrategy = _chunkXOLAXE2Zjs.getSingleFetchDataStrategyImpl.call(void 0,
|
| 527 | getRouter,
|
| 528 | (match) => {
|
| 529 | let M = match;
|
| 530 | return {
|
| 531 | hasLoader: M.route.hasLoader,
|
| 532 | hasClientLoader: M.route.hasClientLoader,
|
| 533 | hasComponent: M.route.hasComponent,
|
| 534 | hasAction: M.route.hasAction,
|
| 535 | hasClientAction: M.route.hasClientAction,
|
| 536 | hasShouldRevalidate: M.route.hasShouldRevalidate
|
| 537 | };
|
| 538 | },
|
| 539 |
|
| 540 | getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation),
|
| 541 | ssr,
|
| 542 | basename,
|
| 543 |
|
| 544 | true,
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 | (match) => {
|
| 549 | let M = match;
|
| 550 | return M.route.hasComponent && !M.route.element;
|
| 551 | }
|
| 552 | );
|
| 553 | return async (args) => args.runClientMiddleware(async () => {
|
| 554 | let context = args.context;
|
| 555 | context.set(renderedRoutesContext, []);
|
| 556 | let results = await dataStrategy(args);
|
| 557 | const renderedRoutesById = new Map();
|
| 558 | for (const route of context.get(renderedRoutesContext)) {
|
| 559 | if (!renderedRoutesById.has(route.id)) {
|
| 560 | renderedRoutesById.set(route.id, []);
|
| 561 | }
|
| 562 | renderedRoutesById.get(route.id).push(route);
|
| 563 | }
|
| 564 | React3.startTransition(() => {
|
| 565 | for (const match of args.matches) {
|
| 566 | const renderedRoutes = renderedRoutesById.get(match.route.id);
|
| 567 | if (renderedRoutes) {
|
| 568 | for (const rendered of renderedRoutes) {
|
| 569 | window.__reactRouterDataRouter.patchRoutes(
|
| 570 | _nullishCoalesce(rendered.parentId, () => ( null)),
|
| 571 | [createRouteFromServerManifest(rendered)],
|
| 572 | true
|
| 573 | );
|
| 574 | }
|
| 575 | }
|
| 576 | }
|
| 577 | });
|
| 578 | return results;
|
| 579 | });
|
| 580 | }
|
| 581 | function getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation) {
|
| 582 | return async (args, basename, trailingSlashAware, targetRoutes) => {
|
| 583 | let { request, context } = args;
|
| 584 | let url = _chunkXOLAXE2Zjs.singleFetchUrl.call(void 0, request.url, basename, trailingSlashAware, "rsc");
|
| 585 | if (request.method === "GET") {
|
| 586 | url = _chunkXOLAXE2Zjs.stripIndexParam.call(void 0, url);
|
| 587 | if (targetRoutes) {
|
| 588 | url.searchParams.set("_routes", targetRoutes.join(","));
|
| 589 | }
|
| 590 | }
|
| 591 | let res = await fetchImplementation(
|
| 592 | new Request(url, await _chunkXOLAXE2Zjs.createRequestInit.call(void 0, request))
|
| 593 | );
|
| 594 | if (res.status >= 400 && !res.headers.has("X-Remix-Response")) {
|
| 595 | throw new (0, _chunkXOLAXE2Zjs.ErrorResponseImpl)(res.status, res.statusText, await res.text());
|
| 596 | }
|
| 597 | _chunkXOLAXE2Zjs.invariant.call(void 0, res.body, "No response body to decode");
|
| 598 | try {
|
| 599 | const payload = await createFromReadableStream(res.body, {
|
| 600 | temporaryReferences: void 0
|
| 601 | });
|
| 602 | if (payload.type === "redirect") {
|
| 603 | return {
|
| 604 | status: res.status,
|
| 605 | data: {
|
| 606 | redirect: {
|
| 607 | redirect: payload.location,
|
| 608 | reload: payload.reload,
|
| 609 | replace: payload.replace,
|
| 610 | revalidate: false,
|
| 611 | status: payload.status
|
| 612 | }
|
| 613 | }
|
| 614 | };
|
| 615 | }
|
| 616 | if (payload.type !== "render") {
|
| 617 | throw new Error("Unexpected payload type");
|
| 618 | }
|
| 619 | context.get(renderedRoutesContext).push(...payload.matches);
|
| 620 | let results = { routes: {} };
|
| 621 | const dataKey = _chunkXOLAXE2Zjs.isMutationMethod.call(void 0, request.method) ? "actionData" : "loaderData";
|
| 622 | for (let [routeId, data] of Object.entries(payload[dataKey] || {})) {
|
| 623 | results.routes[routeId] = { data };
|
| 624 | }
|
| 625 | if (payload.errors) {
|
| 626 | for (let [routeId, error] of Object.entries(payload.errors)) {
|
| 627 | results.routes[routeId] = { error };
|
| 628 | }
|
| 629 | }
|
| 630 | return { status: res.status, data: results };
|
| 631 | } catch (e) {
|
| 632 | throw new Error("Unable to decode RSC response");
|
| 633 | }
|
| 634 | };
|
| 635 | }
|
| 636 | function RSCHydratedRouter({
|
| 637 | createFromReadableStream,
|
| 638 | fetch: fetchImplementation = fetch,
|
| 639 | payload,
|
| 640 | routeDiscovery = "eager",
|
| 641 | getContext
|
| 642 | }) {
|
| 643 | if (payload.type !== "render") throw new Error("Invalid payload type");
|
| 644 | let { router: router2, routeModules } = React3.useMemo(
|
| 645 | () => createRouterFromPayload({
|
| 646 | payload,
|
| 647 | fetchImplementation,
|
| 648 | getContext,
|
| 649 | createFromReadableStream
|
| 650 | }),
|
| 651 | [createFromReadableStream, payload, fetchImplementation, getContext]
|
| 652 | );
|
| 653 | React3.useEffect(() => {
|
| 654 | _chunkXOLAXE2Zjs.setIsHydrated.call(void 0, );
|
| 655 | }, []);
|
| 656 | React3.useLayoutEffect(() => {
|
| 657 | const globalVar = window;
|
| 658 | if (!globalVar.__routerInitialized) {
|
| 659 | globalVar.__routerInitialized = true;
|
| 660 | globalVar.__reactRouterDataRouter.initialize();
|
| 661 | }
|
| 662 | }, []);
|
| 663 | let [{ routes, state }, setState] = React3.useState(() => ({
|
| 664 | routes: cloneRoutes(router2.routes),
|
| 665 | state: router2.state
|
| 666 | }));
|
| 667 | React3.useLayoutEffect(
|
| 668 | () => router2.subscribe((newState) => {
|
| 669 | if (diffRoutes(router2.routes, routes))
|
| 670 | React3.startTransition(() => {
|
| 671 | setState({
|
| 672 | routes: cloneRoutes(router2.routes),
|
| 673 | state: newState
|
| 674 | });
|
| 675 | });
|
| 676 | }),
|
| 677 | [router2.subscribe, routes, router2]
|
| 678 | );
|
| 679 | const transitionEnabledRouter = React3.useMemo(
|
| 680 | () => ({
|
| 681 | ...router2,
|
| 682 | state,
|
| 683 | routes
|
| 684 | }),
|
| 685 | [router2, routes, state]
|
| 686 | );
|
| 687 | React3.useEffect(() => {
|
| 688 | if (routeDiscovery === "lazy" ||
|
| 689 | _optionalChain([window, 'access', _29 => _29.navigator, 'optionalAccess', _30 => _30.connection, 'optionalAccess', _31 => _31.saveData]) === true) {
|
| 690 | return;
|
| 691 | }
|
| 692 | function registerElement(el) {
|
| 693 | let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
|
| 694 | if (!path) {
|
| 695 | return;
|
| 696 | }
|
| 697 | let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
|
| 698 | if (!discoveredPaths.has(pathname)) {
|
| 699 | nextPaths.add(pathname);
|
| 700 | }
|
| 701 | }
|
| 702 | async function fetchPatches() {
|
| 703 | document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
|
| 704 | let paths = Array.from(nextPaths.keys()).filter((path) => {
|
| 705 | if (discoveredPaths.has(path)) {
|
| 706 | nextPaths.delete(path);
|
| 707 | return false;
|
| 708 | }
|
| 709 | return true;
|
| 710 | });
|
| 711 | if (paths.length === 0) {
|
| 712 | return;
|
| 713 | }
|
| 714 | try {
|
| 715 | await fetchAndApplyManifestPatches(
|
| 716 | paths,
|
| 717 | createFromReadableStream,
|
| 718 | fetchImplementation
|
| 719 | );
|
| 720 | } catch (e) {
|
| 721 | console.error("Failed to fetch manifest patches", e);
|
| 722 | }
|
| 723 | }
|
| 724 | let debouncedFetchPatches = debounce(fetchPatches, 100);
|
| 725 | fetchPatches();
|
| 726 | let observer = new MutationObserver(() => debouncedFetchPatches());
|
| 727 | observer.observe(document.documentElement, {
|
| 728 | subtree: true,
|
| 729 | childList: true,
|
| 730 | attributes: true,
|
| 731 | attributeFilter: ["data-discover", "href", "action"]
|
| 732 | });
|
| 733 | }, [routeDiscovery, createFromReadableStream, fetchImplementation]);
|
| 734 | const frameworkContext = {
|
| 735 | future: {
|
| 736 |
|
| 737 |
|
| 738 | v8_middleware: false,
|
| 739 | unstable_subResourceIntegrity: false,
|
| 740 | unstable_trailingSlashAwareDataRequests: true
|
| 741 |
|
| 742 | },
|
| 743 | isSpaMode: false,
|
| 744 | ssr: true,
|
| 745 | criticalCss: "",
|
| 746 | manifest: {
|
| 747 | routes: {},
|
| 748 | version: "1",
|
| 749 | url: "",
|
| 750 | entry: {
|
| 751 | module: "",
|
| 752 | imports: []
|
| 753 | }
|
| 754 | },
|
| 755 | routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
|
| 756 | routeModules
|
| 757 | };
|
| 758 | return React3.createElement(_chunkXOLAXE2Zjs.RSCRouterContext.Provider, { value: true }, React3.createElement(_chunkKSEWV2VOjs.RSCRouterGlobalErrorBoundary, { location: state.location }, React3.createElement(_chunkXOLAXE2Zjs.FrameworkContext.Provider, { value: frameworkContext }, React3.createElement(
|
| 759 | _chunkXOLAXE2Zjs.RouterProvider,
|
| 760 | {
|
| 761 | router: transitionEnabledRouter,
|
| 762 | flushSync: ReactDOM2.flushSync
|
| 763 | }
|
| 764 | ))));
|
| 765 | }
|
| 766 | function createRouteFromServerManifest(match, payload) {
|
| 767 | let hasInitialData = payload && match.id in payload.loaderData;
|
| 768 | let initialData = _optionalChain([payload, 'optionalAccess', _32 => _32.loaderData, 'access', _33 => _33[match.id]]);
|
| 769 | let hasInitialError = _optionalChain([payload, 'optionalAccess', _34 => _34.errors]) && match.id in payload.errors;
|
| 770 | let initialError = _optionalChain([payload, 'optionalAccess', _35 => _35.errors, 'optionalAccess', _36 => _36[match.id]]);
|
| 771 | let isHydrationRequest = _optionalChain([match, 'access', _37 => _37.clientLoader, 'optionalAccess', _38 => _38.hydrate]) === true || !match.hasLoader ||
|
| 772 |
|
| 773 |
|
| 774 | match.hasComponent && !match.element;
|
| 775 | _chunkXOLAXE2Zjs.invariant.call(void 0, window.__reactRouterRouteModules);
|
| 776 | _chunkKSEWV2VOjs.populateRSCRouteModules.call(void 0, window.__reactRouterRouteModules, match);
|
| 777 | let dataRoute = {
|
| 778 | id: match.id,
|
| 779 | element: match.element,
|
| 780 | errorElement: match.errorElement,
|
| 781 | handle: match.handle,
|
| 782 | hasErrorBoundary: match.hasErrorBoundary,
|
| 783 | hydrateFallbackElement: match.hydrateFallbackElement,
|
| 784 | index: match.index,
|
| 785 | loader: match.clientLoader ? async (args, singleFetch) => {
|
| 786 | try {
|
| 787 | let result = await match.clientLoader({
|
| 788 | ...args,
|
| 789 | serverLoader: () => {
|
| 790 | preventInvalidServerHandlerCall(
|
| 791 | "loader",
|
| 792 | match.id,
|
| 793 | match.hasLoader
|
| 794 | );
|
| 795 | if (isHydrationRequest) {
|
| 796 | if (hasInitialData) {
|
| 797 | return initialData;
|
| 798 | }
|
| 799 | if (hasInitialError) {
|
| 800 | throw initialError;
|
| 801 | }
|
| 802 | }
|
| 803 | return callSingleFetch(singleFetch);
|
| 804 | }
|
| 805 | });
|
| 806 | return result;
|
| 807 | } finally {
|
| 808 | isHydrationRequest = false;
|
| 809 | }
|
| 810 | } : (
|
| 811 |
|
| 812 |
|
| 813 | (_, singleFetch) => callSingleFetch(singleFetch)
|
| 814 | ),
|
| 815 | action: match.clientAction ? (args, singleFetch) => match.clientAction({
|
| 816 | ...args,
|
| 817 | serverAction: async () => {
|
| 818 | preventInvalidServerHandlerCall(
|
| 819 | "action",
|
| 820 | match.id,
|
| 821 | match.hasLoader
|
| 822 | );
|
| 823 | return await callSingleFetch(singleFetch);
|
| 824 | }
|
| 825 | }) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : () => {
|
| 826 | throw _chunkXOLAXE2Zjs.noActionDefinedError.call(void 0, "action", match.id);
|
| 827 | },
|
| 828 | path: match.path,
|
| 829 | shouldRevalidate: match.shouldRevalidate,
|
| 830 |
|
| 831 |
|
| 832 | hasLoader: true,
|
| 833 | hasClientLoader: match.clientLoader != null,
|
| 834 | hasAction: match.hasAction,
|
| 835 | hasClientAction: match.clientAction != null,
|
| 836 | hasShouldRevalidate: match.shouldRevalidate != null
|
| 837 | };
|
| 838 | if (typeof dataRoute.loader === "function") {
|
| 839 | dataRoute.loader.hydrate = _chunkXOLAXE2Zjs.shouldHydrateRouteLoader.call(void 0,
|
| 840 | match.id,
|
| 841 | match.clientLoader,
|
| 842 | match.hasLoader,
|
| 843 | false
|
| 844 | );
|
| 845 | }
|
| 846 | return dataRoute;
|
| 847 | }
|
| 848 | function callSingleFetch(singleFetch) {
|
| 849 | _chunkXOLAXE2Zjs.invariant.call(void 0, typeof singleFetch === "function", "Invalid singleFetch parameter");
|
| 850 | return singleFetch();
|
| 851 | }
|
| 852 | function preventInvalidServerHandlerCall(type, routeId, hasHandler) {
|
| 853 | if (!hasHandler) {
|
| 854 | let fn = type === "action" ? "serverAction()" : "serverLoader()";
|
| 855 | let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${routeId}")`;
|
| 856 | console.error(msg);
|
| 857 | throw new (0, _chunkXOLAXE2Zjs.ErrorResponseImpl)(400, "Bad Request", new Error(msg), true);
|
| 858 | }
|
| 859 | }
|
| 860 | var nextPaths = new Set();
|
| 861 | var discoveredPathsMaxSize = 1e3;
|
| 862 | var discoveredPaths = new Set();
|
| 863 | var URL_LIMIT = 7680;
|
| 864 | function getManifestUrl(paths) {
|
| 865 | if (paths.length === 0) {
|
| 866 | return null;
|
| 867 | }
|
| 868 | if (paths.length === 1) {
|
| 869 | return new URL(`${paths[0]}.manifest`, window.location.origin);
|
| 870 | }
|
| 871 | const globalVar = window;
|
| 872 | let basename = (_nullishCoalesce(globalVar.__reactRouterDataRouter.basename, () => ( ""))).replace(
|
| 873 | /^\/|\/$/g,
|
| 874 | ""
|
| 875 | );
|
| 876 | let url = new URL(`${basename}/.manifest`, window.location.origin);
|
| 877 | url.searchParams.set("paths", paths.sort().join(","));
|
| 878 | return url;
|
| 879 | }
|
| 880 | async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fetchImplementation, signal) {
|
| 881 | let url = getManifestUrl(paths);
|
| 882 | if (url == null) {
|
| 883 | return;
|
| 884 | }
|
| 885 | if (url.toString().length > URL_LIMIT) {
|
| 886 | nextPaths.clear();
|
| 887 | return;
|
| 888 | }
|
| 889 | let response = await fetchImplementation(new Request(url, { signal }));
|
| 890 | if (!response.body || response.status < 200 || response.status >= 300) {
|
| 891 | throw new Error("Unable to fetch new route matches from the server");
|
| 892 | }
|
| 893 | let payload = await createFromReadableStream(response.body, {
|
| 894 | temporaryReferences: void 0
|
| 895 | });
|
| 896 | if (payload.type !== "manifest") {
|
| 897 | throw new Error("Failed to patch routes");
|
| 898 | }
|
| 899 | paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
| 900 | React3.startTransition(() => {
|
| 901 | payload.patches.forEach((p) => {
|
| 902 | window.__reactRouterDataRouter.patchRoutes(
|
| 903 | _nullishCoalesce(p.parentId, () => ( null)),
|
| 904 | [createRouteFromServerManifest(p)]
|
| 905 | );
|
| 906 | });
|
| 907 | });
|
| 908 | }
|
| 909 | function addToFifoQueue(path, queue) {
|
| 910 | if (queue.size >= discoveredPathsMaxSize) {
|
| 911 | let first = queue.values().next().value;
|
| 912 | if (typeof first === "string") queue.delete(first);
|
| 913 | }
|
| 914 | queue.add(path);
|
| 915 | }
|
| 916 | function debounce(callback, wait) {
|
| 917 | let timeoutId;
|
| 918 | return (...args) => {
|
| 919 | window.clearTimeout(timeoutId);
|
| 920 | timeoutId = window.setTimeout(() => callback(...args), wait);
|
| 921 | };
|
| 922 | }
|
| 923 | function isExternalLocation(location2) {
|
| 924 | const newLocation = new URL(location2, window.location.href);
|
| 925 | return newLocation.origin !== window.location.origin;
|
| 926 | }
|
| 927 | function cloneRoutes(routes) {
|
| 928 | if (!routes) return void 0;
|
| 929 | return routes.map((route) => ({
|
| 930 | ...route,
|
| 931 | children: cloneRoutes(route.children)
|
| 932 | }));
|
| 933 | }
|
| 934 | function diffRoutes(a, b) {
|
| 935 | if (a.length !== b.length) return true;
|
| 936 | return a.some((route, index) => {
|
| 937 | if (route.element !== b[index].element) return true;
|
| 938 | if (route.errorElement !== b[index].errorElement)
|
| 939 | return true;
|
| 940 | if (route.hydrateFallbackElement !== b[index].hydrateFallbackElement)
|
| 941 | return true;
|
| 942 | if (route.hasErrorBoundary !== b[index].hasErrorBoundary)
|
| 943 | return true;
|
| 944 | if (route.hasLoader !== b[index].hasLoader) return true;
|
| 945 | if (route.hasClientLoader !== b[index].hasClientLoader)
|
| 946 | return true;
|
| 947 | if (route.hasAction !== b[index].hasAction) return true;
|
| 948 | if (route.hasClientAction !== b[index].hasClientAction)
|
| 949 | return true;
|
| 950 | return diffRoutes(route.children || [], b[index].children || []);
|
| 951 | });
|
| 952 | }
|
| 953 |
|
| 954 |
|
| 955 | function getRSCStream() {
|
| 956 | let encoder = new TextEncoder();
|
| 957 | let streamController = null;
|
| 958 | let rscStream = new ReadableStream({
|
| 959 | start(controller) {
|
| 960 | if (typeof window === "undefined") {
|
| 961 | return;
|
| 962 | }
|
| 963 | let handleChunk = (chunk) => {
|
| 964 | if (typeof chunk === "string") {
|
| 965 | controller.enqueue(encoder.encode(chunk));
|
| 966 | } else {
|
| 967 | controller.enqueue(chunk);
|
| 968 | }
|
| 969 | };
|
| 970 | window.__FLIGHT_DATA || (window.__FLIGHT_DATA = []);
|
| 971 | window.__FLIGHT_DATA.forEach(handleChunk);
|
| 972 | window.__FLIGHT_DATA.push = (chunk) => {
|
| 973 | handleChunk(chunk);
|
| 974 | return 0;
|
| 975 | };
|
| 976 | streamController = controller;
|
| 977 | }
|
| 978 | });
|
| 979 | if (typeof document !== "undefined" && document.readyState === "loading") {
|
| 980 | document.addEventListener("DOMContentLoaded", () => {
|
| 981 | _optionalChain([streamController, 'optionalAccess', _39 => _39.close, 'call', _40 => _40()]);
|
| 982 | });
|
| 983 | } else {
|
| 984 | _optionalChain([streamController, 'optionalAccess', _41 => _41.close, 'call', _42 => _42()]);
|
| 985 | }
|
| 986 | return rscStream;
|
| 987 | }
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 | exports.HydratedRouter = HydratedRouter; exports.RouterProvider = RouterProvider2; exports.unstable_RSCHydratedRouter = RSCHydratedRouter; exports.unstable_createCallServer = createCallServer; exports.unstable_getRSCStream = getRSCStream;
|