react-router 0.0.0-experimental-e6fb6e074 → 0.0.0-experimental-2d7ec82d5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +734 -18
  2. package/README.md +5 -14
  3. package/dist/development/chunk-JPPIU5KG.mjs +11511 -0
  4. package/dist/development/data-CQbyyGzl.d.mts +11 -0
  5. package/dist/development/data-CQbyyGzl.d.ts +11 -0
  6. package/dist/development/dom-export.d.mts +23 -0
  7. package/dist/development/dom-export.d.ts +23 -0
  8. package/dist/development/dom-export.js +6347 -0
  9. package/dist/development/dom-export.mjs +222 -0
  10. package/dist/development/fog-of-war-C5L_Yd5M.d.mts +1778 -0
  11. package/dist/development/fog-of-war-DrUCUQQ-.d.ts +1778 -0
  12. package/dist/development/index.d.mts +855 -0
  13. package/dist/development/index.d.ts +855 -0
  14. package/dist/development/index.js +11670 -0
  15. package/dist/development/index.mjs +263 -0
  16. package/dist/development/lib/types/route-module.d.mts +209 -0
  17. package/dist/development/lib/types/route-module.d.ts +209 -0
  18. package/dist/development/lib/types/route-module.js +28 -0
  19. package/dist/development/lib/types/route-module.mjs +10 -0
  20. package/dist/development/route-data-BIYebJr3.d.mts +1749 -0
  21. package/dist/development/route-data-BIYebJr3.d.ts +1749 -0
  22. package/dist/development/rsc-export.d.mts +1788 -0
  23. package/dist/development/rsc-export.d.ts +1788 -0
  24. package/dist/development/rsc-export.js +2784 -0
  25. package/dist/development/rsc-export.mjs +2749 -0
  26. package/dist/production/chunk-O34M5LIX.mjs +11511 -0
  27. package/dist/production/data-CQbyyGzl.d.mts +11 -0
  28. package/dist/production/data-CQbyyGzl.d.ts +11 -0
  29. package/dist/production/dom-export.d.mts +23 -0
  30. package/dist/production/dom-export.d.ts +23 -0
  31. package/dist/production/dom-export.js +6347 -0
  32. package/dist/production/dom-export.mjs +222 -0
  33. package/dist/production/fog-of-war-C5L_Yd5M.d.mts +1778 -0
  34. package/dist/production/fog-of-war-DrUCUQQ-.d.ts +1778 -0
  35. package/dist/production/index.d.mts +855 -0
  36. package/dist/production/index.d.ts +855 -0
  37. package/dist/production/index.js +11670 -0
  38. package/dist/production/index.mjs +263 -0
  39. package/dist/production/lib/types/route-module.d.mts +209 -0
  40. package/dist/production/lib/types/route-module.d.ts +209 -0
  41. package/dist/production/lib/types/route-module.js +28 -0
  42. package/dist/production/lib/types/route-module.mjs +10 -0
  43. package/dist/production/route-data-BIYebJr3.d.mts +1749 -0
  44. package/dist/production/route-data-BIYebJr3.d.ts +1749 -0
  45. package/dist/production/rsc-export.d.mts +1788 -0
  46. package/dist/production/rsc-export.d.ts +1788 -0
  47. package/dist/production/rsc-export.js +2784 -0
  48. package/dist/production/rsc-export.mjs +2749 -0
  49. package/package.json +111 -9
  50. package/dist/index.d.ts +0 -30
  51. package/dist/index.js +0 -1501
  52. package/dist/index.js.map +0 -1
  53. package/dist/lib/components.d.ts +0 -157
  54. package/dist/lib/context.d.ts +0 -102
  55. package/dist/lib/deprecations.d.ts +0 -4
  56. package/dist/lib/hooks.d.ts +0 -181
  57. package/dist/main.js +0 -19
  58. package/dist/react-router.development.js +0 -1397
  59. package/dist/react-router.development.js.map +0 -1
  60. package/dist/react-router.production.min.js +0 -12
  61. package/dist/react-router.production.min.js.map +0 -1
  62. package/dist/umd/react-router.development.js +0 -1624
  63. package/dist/umd/react-router.development.js.map +0 -1
  64. package/dist/umd/react-router.production.min.js +0 -12
  65. package/dist/umd/react-router.production.min.js.map +0 -1
@@ -0,0 +1,222 @@
1
+ /**
2
+ * react-router v0.0.0-experimental-2d7ec82d5
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
+ */
11
+ import {
12
+ FrameworkContext,
13
+ RemixErrorBoundary,
14
+ RouterProvider,
15
+ createBrowserHistory,
16
+ createClientRoutes,
17
+ createClientRoutesWithHMRRevalidationOptOut,
18
+ createRouter,
19
+ decodeViaTurboStream,
20
+ deserializeErrors,
21
+ getHydrationData,
22
+ getPatchRoutesOnNavigationFunction,
23
+ getTurboStreamSingleFetchDataStrategy,
24
+ hydrationRouteProperties,
25
+ invariant,
26
+ mapRouteProperties,
27
+ useFogOFWarDiscovery
28
+ } from "./chunk-JPPIU5KG.mjs";
29
+
30
+ // lib/dom-export/dom-router-provider.tsx
31
+ import * as React from "react";
32
+ import * as ReactDOM from "react-dom";
33
+ function RouterProvider2(props) {
34
+ return /* @__PURE__ */ React.createElement(RouterProvider, { flushSync: ReactDOM.flushSync, ...props });
35
+ }
36
+
37
+ // lib/dom-export/hydrated-router.tsx
38
+ import * as React2 from "react";
39
+ var ssrInfo = null;
40
+ var router = null;
41
+ function initSsrInfo() {
42
+ if (!ssrInfo && window.__reactRouterContext && window.__reactRouterManifest && window.__reactRouterRouteModules) {
43
+ if (window.__reactRouterManifest.sri === true) {
44
+ const importMap = document.querySelector("script[rr-importmap]");
45
+ if (importMap?.textContent) {
46
+ try {
47
+ window.__reactRouterManifest.sri = JSON.parse(
48
+ importMap.textContent
49
+ ).integrity;
50
+ } catch (err) {
51
+ console.error("Failed to parse import map", err);
52
+ }
53
+ }
54
+ }
55
+ ssrInfo = {
56
+ context: window.__reactRouterContext,
57
+ manifest: window.__reactRouterManifest,
58
+ routeModules: window.__reactRouterRouteModules,
59
+ stateDecodingPromise: void 0,
60
+ router: void 0,
61
+ routerInitialized: false
62
+ };
63
+ }
64
+ }
65
+ function createHydratedRouter({
66
+ unstable_getContext
67
+ }) {
68
+ initSsrInfo();
69
+ if (!ssrInfo) {
70
+ throw new Error(
71
+ "You must be using the SSR features of React Router in order to skip passing a `router` prop to `<RouterProvider>`"
72
+ );
73
+ }
74
+ let localSsrInfo = ssrInfo;
75
+ if (!ssrInfo.stateDecodingPromise) {
76
+ let stream = ssrInfo.context.stream;
77
+ invariant(stream, "No stream found for single fetch decoding");
78
+ ssrInfo.context.stream = void 0;
79
+ ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then((value) => {
80
+ ssrInfo.context.state = value.value;
81
+ localSsrInfo.stateDecodingPromise.value = true;
82
+ }).catch((e) => {
83
+ localSsrInfo.stateDecodingPromise.error = e;
84
+ });
85
+ }
86
+ if (ssrInfo.stateDecodingPromise.error) {
87
+ throw ssrInfo.stateDecodingPromise.error;
88
+ }
89
+ if (!ssrInfo.stateDecodingPromise.value) {
90
+ throw ssrInfo.stateDecodingPromise;
91
+ }
92
+ let routes = createClientRoutes(
93
+ ssrInfo.manifest.routes,
94
+ ssrInfo.routeModules,
95
+ ssrInfo.context.state,
96
+ ssrInfo.context.ssr,
97
+ ssrInfo.context.isSpaMode
98
+ );
99
+ let hydrationData = void 0;
100
+ if (ssrInfo.context.isSpaMode) {
101
+ let { loaderData } = ssrInfo.context.state;
102
+ if (ssrInfo.manifest.routes.root?.hasLoader && loaderData && "root" in loaderData) {
103
+ hydrationData = {
104
+ loaderData: {
105
+ root: loaderData.root
106
+ }
107
+ };
108
+ }
109
+ } else {
110
+ hydrationData = getHydrationData(
111
+ ssrInfo.context.state,
112
+ routes,
113
+ (routeId) => ({
114
+ clientLoader: ssrInfo.routeModules[routeId]?.clientLoader,
115
+ hasLoader: ssrInfo.manifest.routes[routeId]?.hasLoader === true,
116
+ hasHydrateFallback: ssrInfo.routeModules[routeId]?.HydrateFallback != null
117
+ }),
118
+ window.location,
119
+ window.__reactRouterContext?.basename,
120
+ ssrInfo.context.isSpaMode
121
+ );
122
+ if (hydrationData && hydrationData.errors) {
123
+ hydrationData.errors = deserializeErrors(hydrationData.errors);
124
+ }
125
+ }
126
+ let router2 = createRouter({
127
+ routes,
128
+ history: createBrowserHistory(),
129
+ basename: ssrInfo.context.basename,
130
+ unstable_getContext,
131
+ hydrationData,
132
+ hydrationRouteProperties,
133
+ mapRouteProperties,
134
+ future: {
135
+ unstable_middleware: ssrInfo.context.future.unstable_middleware
136
+ },
137
+ dataStrategy: getTurboStreamSingleFetchDataStrategy(
138
+ () => router2,
139
+ ssrInfo.manifest,
140
+ ssrInfo.routeModules,
141
+ ssrInfo.context.ssr,
142
+ ssrInfo.context.basename
143
+ ),
144
+ patchRoutesOnNavigation: getPatchRoutesOnNavigationFunction(
145
+ ssrInfo.manifest,
146
+ ssrInfo.routeModules,
147
+ ssrInfo.context.ssr,
148
+ ssrInfo.context.isSpaMode,
149
+ ssrInfo.context.basename
150
+ )
151
+ });
152
+ ssrInfo.router = router2;
153
+ if (router2.state.initialized) {
154
+ ssrInfo.routerInitialized = true;
155
+ router2.initialize();
156
+ }
157
+ router2.createRoutesForHMR = /* spacer so ts-ignore does not affect the right hand of the assignment */
158
+ createClientRoutesWithHMRRevalidationOptOut;
159
+ window.__reactRouterDataRouter = router2;
160
+ return router2;
161
+ }
162
+ function HydratedRouter(props) {
163
+ if (!router) {
164
+ router = createHydratedRouter({
165
+ unstable_getContext: props.unstable_getContext
166
+ });
167
+ }
168
+ let [criticalCss, setCriticalCss] = React2.useState(
169
+ process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0
170
+ );
171
+ if (process.env.NODE_ENV === "development") {
172
+ if (ssrInfo) {
173
+ window.__reactRouterClearCriticalCss = () => setCriticalCss(void 0);
174
+ }
175
+ }
176
+ let [location, setLocation] = React2.useState(router.state.location);
177
+ React2.useLayoutEffect(() => {
178
+ if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
179
+ ssrInfo.routerInitialized = true;
180
+ ssrInfo.router.initialize();
181
+ }
182
+ }, []);
183
+ React2.useLayoutEffect(() => {
184
+ if (ssrInfo && ssrInfo.router) {
185
+ return ssrInfo.router.subscribe((newState) => {
186
+ if (newState.location !== location) {
187
+ setLocation(newState.location);
188
+ }
189
+ });
190
+ }
191
+ }, [location]);
192
+ invariant(ssrInfo, "ssrInfo unavailable for HydratedRouter");
193
+ useFogOFWarDiscovery(
194
+ router,
195
+ ssrInfo.manifest,
196
+ ssrInfo.routeModules,
197
+ ssrInfo.context.ssr,
198
+ ssrInfo.context.isSpaMode
199
+ );
200
+ return (
201
+ // This fragment is important to ensure we match the <ServerRouter> JSX
202
+ // structure so that useId values hydrate correctly
203
+ /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
204
+ FrameworkContext.Provider,
205
+ {
206
+ value: {
207
+ manifest: ssrInfo.manifest,
208
+ routeModules: ssrInfo.routeModules,
209
+ future: ssrInfo.context.future,
210
+ criticalCss,
211
+ ssr: ssrInfo.context.ssr,
212
+ isSpaMode: ssrInfo.context.isSpaMode
213
+ }
214
+ },
215
+ /* @__PURE__ */ React2.createElement(RemixErrorBoundary, { location }, /* @__PURE__ */ React2.createElement(RouterProvider2, { router }))
216
+ ), /* @__PURE__ */ React2.createElement(React2.Fragment, null))
217
+ );
218
+ }
219
+ export {
220
+ HydratedRouter,
221
+ RouterProvider2 as RouterProvider
222
+ };