one 1.2.20 → 1.2.22-1765155190908
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.
- package/dist/cjs/cli/build.cjs +11 -2
- package/dist/cjs/cli/build.js +10 -2
- package/dist/cjs/cli/build.js.map +1 -1
- package/dist/cjs/cli/build.native.js +44 -19
- package/dist/cjs/cli/build.native.js.map +1 -1
- package/dist/cjs/cli/buildPage.cjs +20 -4
- package/dist/cjs/cli/buildPage.js +21 -7
- package/dist/cjs/cli/buildPage.js.map +1 -1
- package/dist/cjs/cli/buildPage.native.js +38 -6
- package/dist/cjs/cli/buildPage.native.js.map +1 -1
- package/dist/cjs/createApp.cjs +23 -16
- package/dist/cjs/createApp.js +73 -67
- package/dist/cjs/createApp.js.map +2 -2
- package/dist/cjs/createHandleRequest.cjs +10 -6
- package/dist/cjs/createHandleRequest.js +10 -6
- package/dist/cjs/createHandleRequest.js.map +1 -1
- package/dist/cjs/createHandleRequest.native.js +11 -7
- package/dist/cjs/createHandleRequest.native.js.map +1 -1
- package/dist/cjs/fork/NavigationContainer.cjs +1 -1
- package/dist/cjs/fork/NavigationContainer.js +4 -1
- package/dist/cjs/fork/NavigationContainer.js.map +1 -1
- package/dist/cjs/fork/NavigationContainer.native.js +1 -1
- package/dist/cjs/fork/NavigationContainer.native.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.cjs +2 -2
- package/dist/cjs/fork/createMemoryHistory.js +2 -2
- package/dist/cjs/fork/createMemoryHistory.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.native.js +2 -2
- package/dist/cjs/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/cjs/fork/extractPathFromURL.cjs +1 -1
- package/dist/cjs/fork/extractPathFromURL.js +1 -1
- package/dist/cjs/fork/extractPathFromURL.js.map +1 -1
- package/dist/cjs/fork/extractPathFromURL.native.js +1 -1
- package/dist/cjs/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.cjs +1 -1
- package/dist/cjs/fork/getPathFromState-mods.js +1 -1
- package/dist/cjs/fork/getPathFromState-mods.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.native.js +1 -1
- package/dist/cjs/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath-mods.cjs +20 -19
- package/dist/cjs/fork/getStateFromPath-mods.js +18 -15
- package/dist/cjs/fork/getStateFromPath-mods.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath-mods.native.js +19 -18
- package/dist/cjs/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath.cjs +1 -1
- package/dist/cjs/fork/getStateFromPath.js +1 -1
- package/dist/cjs/fork/getStateFromPath.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath.native.js +1 -1
- package/dist/cjs/fork/getStateFromPath.native.js.map +1 -1
- package/dist/cjs/fork/useLinking.cjs +27 -20
- package/dist/cjs/fork/useLinking.js +32 -20
- package/dist/cjs/fork/useLinking.js.map +2 -2
- package/dist/cjs/fork/useLinking.native.js +2 -1
- package/dist/cjs/fork/useLinking.native.js.map +1 -1
- package/dist/cjs/getReactNavigationConfig.cjs +2 -4
- package/dist/cjs/getReactNavigationConfig.js +2 -5
- package/dist/cjs/getReactNavigationConfig.js.map +1 -1
- package/dist/cjs/getReactNavigationConfig.native.js +2 -4
- package/dist/cjs/getReactNavigationConfig.native.js.map +1 -1
- package/dist/cjs/hooks.cjs +1 -1
- package/dist/cjs/hooks.js +1 -1
- package/dist/cjs/hooks.js.map +1 -1
- package/dist/cjs/hooks.native.js +4 -1
- package/dist/cjs/hooks.native.js.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +2 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/router/getRoutes.cjs +4 -5
- package/dist/cjs/router/getRoutes.js +2 -2
- package/dist/cjs/router/getRoutes.js.map +1 -1
- package/dist/cjs/router/getRoutes.native.js +4 -5
- package/dist/cjs/router/getRoutes.native.js.map +1 -1
- package/dist/cjs/router/matchers.cjs +9 -1
- package/dist/cjs/router/matchers.js +4 -1
- package/dist/cjs/router/matchers.js.map +1 -1
- package/dist/cjs/router/matchers.native.js +10 -2
- package/dist/cjs/router/matchers.native.js.map +1 -1
- package/dist/cjs/router/matchers.test.cjs +7 -1
- package/dist/cjs/router/matchers.test.js +1 -1
- package/dist/cjs/router/matchers.test.js.map +1 -1
- package/dist/cjs/router/matchers.test.native.js +7 -1
- package/dist/cjs/router/matchers.test.native.js.map +1 -1
- package/dist/cjs/router/router.cjs +20 -17
- package/dist/cjs/router/router.js +24 -21
- package/dist/cjs/router/router.js.map +1 -1
- package/dist/cjs/router/router.native.js +21 -18
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/router/useViteRoutes.cjs +57 -17
- package/dist/cjs/router/useViteRoutes.js +55 -17
- package/dist/cjs/router/useViteRoutes.js.map +2 -2
- package/dist/cjs/router/useViteRoutes.native.js +76 -0
- package/dist/cjs/router/useViteRoutes.native.js.map +1 -1
- package/dist/cjs/router/utils/getNavigateAction.cjs +2 -2
- package/dist/cjs/router/utils/getNavigateAction.js +2 -2
- package/dist/cjs/router/utils/getNavigateAction.js.map +1 -1
- package/dist/cjs/router/utils/getNavigateAction.native.js +2 -2
- package/dist/cjs/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/cjs/server/oneServe.cjs +4 -3
- package/dist/cjs/server/oneServe.js +6 -3
- package/dist/cjs/server/oneServe.js.map +1 -1
- package/dist/cjs/server/oneServe.native.js +5 -4
- package/dist/cjs/server/oneServe.native.js.map +1 -1
- package/dist/cjs/useLoader.cjs +39 -40
- package/dist/cjs/useLoader.js +10 -7
- package/dist/cjs/useLoader.js.map +1 -1
- package/dist/cjs/useLoader.native.js +54 -54
- package/dist/cjs/useLoader.native.js.map +1 -1
- package/dist/cjs/vite/one.cjs +9 -12
- package/dist/cjs/vite/one.js +7 -7
- package/dist/cjs/vite/one.js.map +1 -1
- package/dist/cjs/vite/one.native.js +10 -15
- package/dist/cjs/vite/one.native.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +12 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +11 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +12 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.js +12 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +12 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/dist/esm/cli/build.js +10 -2
- package/dist/esm/cli/build.js.map +1 -1
- package/dist/esm/cli/build.mjs +11 -2
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +44 -19
- package/dist/esm/cli/build.native.js.map +1 -1
- package/dist/esm/cli/buildPage.js +21 -7
- package/dist/esm/cli/buildPage.js.map +1 -1
- package/dist/esm/cli/buildPage.mjs +20 -4
- package/dist/esm/cli/buildPage.mjs.map +1 -1
- package/dist/esm/cli/buildPage.native.js +38 -6
- package/dist/esm/cli/buildPage.native.js.map +1 -1
- package/dist/esm/createApp.js +73 -66
- package/dist/esm/createApp.js.map +2 -2
- package/dist/esm/createApp.mjs +23 -16
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/createHandleRequest.js +10 -6
- package/dist/esm/createHandleRequest.js.map +1 -1
- package/dist/esm/createHandleRequest.mjs +10 -6
- package/dist/esm/createHandleRequest.mjs.map +1 -1
- package/dist/esm/createHandleRequest.native.js +10 -6
- package/dist/esm/createHandleRequest.native.js.map +1 -1
- package/dist/esm/fork/NavigationContainer.js +4 -1
- package/dist/esm/fork/NavigationContainer.js.map +1 -1
- package/dist/esm/fork/NavigationContainer.mjs +1 -1
- package/dist/esm/fork/NavigationContainer.mjs.map +1 -1
- package/dist/esm/fork/NavigationContainer.native.js +1 -1
- package/dist/esm/fork/NavigationContainer.native.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.js +2 -2
- package/dist/esm/fork/createMemoryHistory.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.mjs +2 -2
- package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
- package/dist/esm/fork/createMemoryHistory.native.js +2 -2
- package/dist/esm/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.js +1 -1
- package/dist/esm/fork/extractPathFromURL.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.mjs +1 -1
- package/dist/esm/fork/extractPathFromURL.mjs.map +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.js +2 -2
- package/dist/esm/fork/getPathFromState-mods.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.mjs +2 -2
- package/dist/esm/fork/getPathFromState-mods.mjs.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.native.js +2 -2
- package/dist/esm/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.js +18 -15
- package/dist/esm/fork/getStateFromPath-mods.js.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.mjs +20 -19
- package/dist/esm/fork/getStateFromPath-mods.mjs.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.native.js +19 -18
- package/dist/esm/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/esm/fork/getStateFromPath.js +1 -1
- package/dist/esm/fork/getStateFromPath.js.map +1 -1
- package/dist/esm/fork/getStateFromPath.mjs +1 -1
- package/dist/esm/fork/getStateFromPath.mjs.map +1 -1
- package/dist/esm/fork/getStateFromPath.native.js +1 -1
- package/dist/esm/fork/useLinking.js +32 -19
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +27 -20
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/fork/useLinking.native.js +2 -1
- package/dist/esm/fork/useLinking.native.js.map +1 -1
- package/dist/esm/getReactNavigationConfig.js +3 -6
- package/dist/esm/getReactNavigationConfig.js.map +1 -1
- package/dist/esm/getReactNavigationConfig.mjs +3 -5
- package/dist/esm/getReactNavigationConfig.mjs.map +1 -1
- package/dist/esm/getReactNavigationConfig.native.js +3 -5
- package/dist/esm/getReactNavigationConfig.native.js.map +1 -1
- package/dist/esm/hooks.js +1 -1
- package/dist/esm/hooks.js.map +1 -1
- package/dist/esm/hooks.mjs +1 -1
- package/dist/esm/hooks.mjs.map +1 -1
- package/dist/esm/hooks.native.js +4 -1
- package/dist/esm/hooks.native.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/router/getRoutes.js +2 -3
- package/dist/esm/router/getRoutes.js.map +1 -1
- package/dist/esm/router/getRoutes.mjs +5 -6
- package/dist/esm/router/getRoutes.mjs.map +1 -1
- package/dist/esm/router/getRoutes.native.js +5 -6
- package/dist/esm/router/getRoutes.native.js.map +1 -1
- package/dist/esm/router/matchers.js +4 -1
- package/dist/esm/router/matchers.js.map +1 -1
- package/dist/esm/router/matchers.mjs +9 -1
- package/dist/esm/router/matchers.mjs.map +1 -1
- package/dist/esm/router/matchers.native.js +10 -2
- package/dist/esm/router/matchers.native.js.map +1 -1
- package/dist/esm/router/matchers.test.js +1 -1
- package/dist/esm/router/matchers.test.js.map +1 -1
- package/dist/esm/router/matchers.test.mjs +7 -1
- package/dist/esm/router/matchers.test.mjs.map +1 -1
- package/dist/esm/router/matchers.test.native.js +7 -1
- package/dist/esm/router/matchers.test.native.js.map +1 -1
- package/dist/esm/router/router.js +24 -20
- package/dist/esm/router/router.js.map +1 -1
- package/dist/esm/router/router.mjs +20 -18
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +21 -19
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/router/useViteRoutes.js +55 -17
- package/dist/esm/router/useViteRoutes.js.map +1 -1
- package/dist/esm/router/useViteRoutes.mjs +54 -18
- package/dist/esm/router/useViteRoutes.mjs.map +1 -1
- package/dist/esm/router/useViteRoutes.native.js +73 -1
- package/dist/esm/router/useViteRoutes.native.js.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.js +2 -2
- package/dist/esm/router/utils/getNavigateAction.js.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.mjs +2 -2
- package/dist/esm/router/utils/getNavigateAction.mjs.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.native.js +2 -2
- package/dist/esm/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/esm/server/oneServe.js +6 -3
- package/dist/esm/server/oneServe.js.map +1 -1
- package/dist/esm/server/oneServe.mjs +4 -3
- package/dist/esm/server/oneServe.mjs.map +1 -1
- package/dist/esm/server/oneServe.native.js +4 -3
- package/dist/esm/server/oneServe.native.js.map +1 -1
- package/dist/esm/useLoader.js +10 -8
- package/dist/esm/useLoader.js.map +1 -1
- package/dist/esm/useLoader.mjs +40 -41
- package/dist/esm/useLoader.mjs.map +1 -1
- package/dist/esm/useLoader.native.js +55 -55
- package/dist/esm/useLoader.native.js.map +1 -1
- package/dist/esm/vite/one.js +9 -9
- package/dist/esm/vite/one.js.map +1 -1
- package/dist/esm/vite/one.mjs +9 -12
- package/dist/esm/vite/one.mjs.map +1 -1
- package/dist/esm/vite/one.native.js +10 -15
- package/dist/esm/vite/one.native.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +11 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +12 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.js +12 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +12 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +12 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/package.json +10 -10
- package/src/cli/build.ts +26 -1
- package/src/cli/buildPage.ts +28 -5
- package/src/createApp.tsx +29 -21
- package/src/createHandleRequest.ts +34 -0
- package/src/fork/NavigationContainer.tsx +8 -0
- package/src/fork/createMemoryHistory.tsx +8 -0
- package/src/fork/extractPathFromURL.ts +6 -0
- package/src/fork/getPathFromState-mods.ts +2 -7
- package/src/fork/getStateFromPath-mods.ts +43 -17
- package/src/fork/getStateFromPath.ts +1 -1
- package/src/fork/useLinking.native.ts +1 -1
- package/src/fork/useLinking.ts +89 -5
- package/src/getReactNavigationConfig.ts +7 -9
- package/src/hooks.tsx +21 -19
- package/src/index.ts +1 -0
- package/src/router/getRoutes.ts +3 -6
- package/src/router/matchers.test.ts +2 -2
- package/src/router/matchers.ts +22 -6
- package/src/router/router.ts +39 -26
- package/src/router/useViteRoutes.tsx +127 -17
- package/src/router/utils/getNavigateAction.ts +3 -2
- package/src/server/oneServe.ts +13 -0
- package/src/types.ts +1 -0
- package/src/useLoader.ts +20 -12
- package/src/vite/one.ts +9 -13
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +17 -5
- package/src/vite/plugins/virtualEntryPlugin.ts +12 -1
- package/src/vite/types.ts +2 -0
- package/types/cli/build.d.ts.map +1 -1
- package/types/cli/buildPage.d.ts +1 -1
- package/types/cli/buildPage.d.ts.map +1 -1
- package/types/createApp.d.ts.map +1 -1
- package/types/createHandleRequest.d.ts.map +1 -1
- package/types/fork/NavigationContainer.d.ts.map +1 -1
- package/types/fork/createMemoryHistory.d.ts.map +1 -1
- package/types/fork/extractPathFromURL.d.ts.map +1 -1
- package/types/fork/getStateFromPath-mods.d.ts +7 -10
- package/types/fork/getStateFromPath-mods.d.ts.map +1 -1
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/getReactNavigationConfig.d.ts.map +1 -1
- package/types/hooks.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/router/getRoutes.d.ts.map +1 -1
- package/types/router/matchers.d.ts +10 -3
- package/types/router/matchers.d.ts.map +1 -1
- package/types/router/router.d.ts +3 -2
- package/types/router/router.d.ts.map +1 -1
- package/types/router/useViteRoutes.d.ts +11 -0
- package/types/router/useViteRoutes.d.ts.map +1 -1
- package/types/router/utils/getNavigateAction.d.ts.map +1 -1
- package/types/server/oneServe.d.ts.map +1 -1
- package/types/types.d.ts +1 -0
- package/types/types.d.ts.map +1 -1
- package/types/useLoader.d.ts.map +1 -1
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
- package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
- package/types/vite/types.d.ts +1 -0
- package/types/vite/types.d.ts.map +1 -1
package/src/hooks.tsx
CHANGED
|
@@ -133,24 +133,26 @@ export function useParams<TParams extends Object = SearchParams>(): Partial<TPar
|
|
|
133
133
|
const params = React.useContext(RouteParamsContext) ?? {}
|
|
134
134
|
|
|
135
135
|
return Object.fromEntries(
|
|
136
|
-
Object.entries(params)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
136
|
+
Object.entries(params)
|
|
137
|
+
.filter(([_, value]) => value !== undefined)
|
|
138
|
+
.map(([key, value]) => {
|
|
139
|
+
if (Array.isArray(value)) {
|
|
140
|
+
return [
|
|
141
|
+
key,
|
|
142
|
+
value.map((v) => {
|
|
143
|
+
try {
|
|
144
|
+
return decodeURIComponent(v)
|
|
145
|
+
} catch {
|
|
146
|
+
return v
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
return [key, decodeURIComponent(value as string)]
|
|
153
|
+
} catch {
|
|
154
|
+
return [key, value]
|
|
155
|
+
}
|
|
156
|
+
})
|
|
155
157
|
) as TParams
|
|
156
158
|
}
|
package/src/index.ts
CHANGED
|
@@ -66,6 +66,7 @@ export { createRoute, route } from './router/createRoute'
|
|
|
66
66
|
export { router } from './router/imperative-api'
|
|
67
67
|
export * as routerStore from './router/router'
|
|
68
68
|
export { useNavigation } from './router/useNavigation'
|
|
69
|
+
export { registerPreloadedRoute } from './router/useViteRoutes'
|
|
69
70
|
export type { Endpoint, LoaderProps } from './types'
|
|
70
71
|
// React Navigation
|
|
71
72
|
export { useFocusEffect } from './useFocusEffect'
|
package/src/router/getRoutes.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { getPageExport } from '../utils/getPageExport'
|
|
|
3
3
|
import type { One } from '../vite/types'
|
|
4
4
|
import {
|
|
5
5
|
matchArrayGroupName,
|
|
6
|
-
matchDeepDynamicRouteName,
|
|
7
6
|
matchDynamicName,
|
|
8
7
|
matchGroupName,
|
|
9
8
|
removeSupportedExtensions,
|
|
@@ -479,11 +478,9 @@ export function generateDynamic(path: string): DynamicConvention[] | null {
|
|
|
479
478
|
}
|
|
480
479
|
}
|
|
481
480
|
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (!dynamicName) return null
|
|
486
|
-
return { name: dynamicName, deep: !!deepDynamicName }
|
|
481
|
+
const dynamicMatch = matchDynamicName(part)
|
|
482
|
+
if (!dynamicMatch) return null
|
|
483
|
+
return { name: dynamicMatch.name, deep: dynamicMatch.deep }
|
|
487
484
|
})
|
|
488
485
|
.filter((part): part is DynamicConvention => !!part)
|
|
489
486
|
|
|
@@ -46,8 +46,8 @@ describe(matchDynamicName, () => {
|
|
|
46
46
|
it(`matches`, () => {
|
|
47
47
|
expect(matchDynamicName('[[...foobar]]')).toEqual(undefined)
|
|
48
48
|
expect(matchDynamicName('[[foobar]]')).toEqual(undefined)
|
|
49
|
-
expect(matchDynamicName('[...foobar]')).toEqual(
|
|
50
|
-
expect(matchDynamicName('[foobar]')).toEqual('foobar')
|
|
49
|
+
expect(matchDynamicName('[...foobar]')).toEqual({ name: 'foobar', deep: true })
|
|
50
|
+
expect(matchDynamicName('[foobar]')).toEqual({ name: 'foobar', deep: false })
|
|
51
51
|
expect(matchDynamicName('foobar')).toEqual(undefined)
|
|
52
52
|
})
|
|
53
53
|
})
|
package/src/router/matchers.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
/** Match `[page]` -> `page` */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** Match `[page]` -> `page` or `[...page]` -> `page` with deep flag */
|
|
2
|
+
const dynamicNameRe = /^\[([^[\]]+?)\]$/
|
|
3
|
+
|
|
4
|
+
export interface DynamicNameMatch {
|
|
5
|
+
name: string
|
|
6
|
+
deep: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Match `[page]` -> `{ name: 'page', deep: false }` or `[...page]` -> `{ name: 'page', deep: true }` */
|
|
10
|
+
export function matchDynamicName(name: string): DynamicNameMatch | undefined {
|
|
11
|
+
const paramName = name.match(dynamicNameRe)?.[1]
|
|
12
|
+
if (paramName == null) {
|
|
13
|
+
return undefined
|
|
14
|
+
} else if (paramName.startsWith('...')) {
|
|
15
|
+
return { name: paramName.slice(3), deep: true }
|
|
16
|
+
} else {
|
|
17
|
+
return { name: paramName, deep: false }
|
|
18
|
+
}
|
|
6
19
|
}
|
|
7
20
|
|
|
8
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Match `[...page]` -> `page`
|
|
23
|
+
* @deprecated Use matchDynamicName instead which returns {name, deep}
|
|
24
|
+
*/
|
|
9
25
|
export function matchDeepDynamicRouteName(name: string): string | undefined {
|
|
10
26
|
return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1]
|
|
11
27
|
}
|
package/src/router/router.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { getLinking, resetLinking, setupLinking } from './linkingConfig'
|
|
|
24
24
|
import type { RouteNode } from './Route'
|
|
25
25
|
import { sortRoutes } from './sortRoutes'
|
|
26
26
|
import { getQualifiedRouteComponent } from './useScreens'
|
|
27
|
+
import { preloadRouteModules } from './useViteRoutes'
|
|
27
28
|
import { getNavigateAction } from './utils/getNavigateAction'
|
|
28
29
|
|
|
29
30
|
// Module-scoped variables
|
|
@@ -65,7 +66,7 @@ export function initialize(
|
|
|
65
66
|
throw new Error('No routes found')
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
if (process.env.
|
|
69
|
+
if (process.env.ONE_DEBUG_ROUTER && routeNode) {
|
|
69
70
|
const formatRouteTree = (node: RouteNode, indent = '', isLast = true): string => {
|
|
70
71
|
const prefix = indent + (isLast ? '└─ ' : '├─ ')
|
|
71
72
|
const childIndent = indent + (isLast ? ' ' : '│ ')
|
|
@@ -180,7 +181,7 @@ export function push(url: OneRouter.Href, options?: OneRouter.LinkToOptions) {
|
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
export function dismiss(count?: number) {
|
|
183
|
-
if (process.env.
|
|
184
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
184
185
|
console.info(`[one] 🔙 dismiss${count ? ` (${count})` : ''}`)
|
|
185
186
|
}
|
|
186
187
|
navigationRef?.dispatch(StackActions.pop(count))
|
|
@@ -199,14 +200,14 @@ export function setParams(params: OneRouter.InpurRouteParamsGeneric = {}) {
|
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
export function dismissAll() {
|
|
202
|
-
if (process.env.
|
|
203
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
203
204
|
console.info(`[one] 🔙 dismissAll`)
|
|
204
205
|
}
|
|
205
206
|
navigationRef?.dispatch(StackActions.popToTop())
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
export function goBack() {
|
|
209
|
-
if (process.env.
|
|
210
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
210
211
|
console.info(`[one] 🔙 goBack`)
|
|
211
212
|
}
|
|
212
213
|
assertIsReady(navigationRef)
|
|
@@ -250,7 +251,7 @@ export function updateState(state: OneRouter.ResultState, nextStateParam = state
|
|
|
250
251
|
const nextRouteInfo = getRouteInfo(state)
|
|
251
252
|
|
|
252
253
|
if (!deepEqual(routeInfo, nextRouteInfo)) {
|
|
253
|
-
if (process.env.
|
|
254
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
254
255
|
const from = routeInfo?.pathname || '(initial)'
|
|
255
256
|
const to = nextRouteInfo.pathname
|
|
256
257
|
const params = Object.keys(nextRouteInfo.params || {}).length
|
|
@@ -367,42 +368,53 @@ export function cleanup() {
|
|
|
367
368
|
}
|
|
368
369
|
|
|
369
370
|
// TODO
|
|
370
|
-
export const preloadingLoader = {}
|
|
371
|
-
|
|
372
|
-
function
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
console.error(`Error preloading loader: ${err}`)
|
|
371
|
+
export const preloadingLoader: Record<string, Promise<any> | undefined> = {}
|
|
372
|
+
|
|
373
|
+
async function doPreload(href: string) {
|
|
374
|
+
const preloadPath = getPreloadPath(href)
|
|
375
|
+
const loaderPath = getLoaderPath(href)
|
|
376
|
+
try {
|
|
377
|
+
const [_preload, loader] = await Promise.all([
|
|
378
|
+
dynamicImport(preloadPath),
|
|
379
|
+
dynamicImport(loaderPath),
|
|
380
|
+
preloadRouteModules(href),
|
|
381
|
+
])
|
|
382
|
+
|
|
383
|
+
if (!loader?.loader) {
|
|
384
384
|
return null
|
|
385
385
|
}
|
|
386
|
+
|
|
387
|
+
const result = await loader.loader()
|
|
388
|
+
return result ?? null
|
|
389
|
+
} catch (err) {
|
|
390
|
+
console.error(`[one] preload error for ${href}:`, err)
|
|
391
|
+
return null
|
|
386
392
|
}
|
|
387
393
|
}
|
|
388
394
|
|
|
389
|
-
|
|
395
|
+
// Store resolved preload data separately from promises
|
|
396
|
+
export const preloadedLoaderData: Record<string, any> = {}
|
|
397
|
+
|
|
398
|
+
export function preloadRoute(href: string): Promise<any> | undefined {
|
|
390
399
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
391
|
-
// not enabled for now
|
|
392
400
|
return
|
|
393
401
|
}
|
|
394
402
|
if (process.env.NODE_ENV === 'development') {
|
|
395
403
|
return
|
|
396
404
|
}
|
|
397
405
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
406
|
+
if (!preloadingLoader[href]) {
|
|
407
|
+
preloadingLoader[href] = doPreload(href).then((data) => {
|
|
408
|
+
// Store the resolved data for synchronous access
|
|
409
|
+
preloadedLoaderData[href] = data
|
|
410
|
+
return data
|
|
411
|
+
})
|
|
401
412
|
}
|
|
413
|
+
return preloadingLoader[href]
|
|
402
414
|
}
|
|
403
415
|
|
|
404
416
|
export async function linkTo(href: string, event?: string, options?: OneRouter.LinkToOptions) {
|
|
405
|
-
if (process.env.
|
|
417
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
406
418
|
console.info(`[one] 🔗 ${event || 'NAVIGATE'} ${href}`)
|
|
407
419
|
}
|
|
408
420
|
|
|
@@ -477,7 +489,8 @@ export async function linkTo(href: string, event?: string, options?: OneRouter.L
|
|
|
477
489
|
|
|
478
490
|
setLoadingState('loading')
|
|
479
491
|
|
|
480
|
-
|
|
492
|
+
// await preload on web to ensure route modules are loaded before navigating
|
|
493
|
+
await preloadRoute(href)
|
|
481
494
|
|
|
482
495
|
const rootState = navigationRef.getRootState()
|
|
483
496
|
|
|
@@ -26,6 +26,125 @@ export function useViteRoutes(
|
|
|
26
26
|
return context
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// store preloaded modules so resolve() can use them synchronously
|
|
30
|
+
let preloadedModules: Record<string, any> = {}
|
|
31
|
+
|
|
32
|
+
export function registerPreloadedRoute(key: string, module: any): void {
|
|
33
|
+
preloadedModules[key] = module
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getPreloadedModule(key: string): any {
|
|
37
|
+
return preloadedModules[key]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getPreloadedModuleKeys(): string[] {
|
|
41
|
+
return Object.keys(preloadedModules)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a dynamic route pattern matches an actual path.
|
|
46
|
+
* Used to preload route modules for dynamic routes like [slug].
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* matchDynamicRoute("docs/[slug]", "docs/getting-started") // true
|
|
50
|
+
* matchDynamicRoute("[...slug]", "a/b/c") // true (catch-all)
|
|
51
|
+
*/
|
|
52
|
+
function matchDynamicRoute(routePattern: string, actualPath: string): boolean {
|
|
53
|
+
const routeSegments = routePattern.split('/')
|
|
54
|
+
const pathSegments = actualPath.split('/')
|
|
55
|
+
|
|
56
|
+
// handle catch-all routes like [...slug]
|
|
57
|
+
const hasCatchAll = routeSegments.some((s) => s.startsWith('[...'))
|
|
58
|
+
if (hasCatchAll) {
|
|
59
|
+
// find the catch-all segment position
|
|
60
|
+
const catchAllIdx = routeSegments.findIndex((s) => s.startsWith('[...'))
|
|
61
|
+
// all segments before catch-all must match exactly (or be dynamic)
|
|
62
|
+
for (let i = 0; i < catchAllIdx; i++) {
|
|
63
|
+
if (!routeSegments[i]) continue
|
|
64
|
+
if (routeSegments[i].startsWith('[')) continue // dynamic segment matches anything
|
|
65
|
+
if (routeSegments[i] !== pathSegments[i]) return false
|
|
66
|
+
}
|
|
67
|
+
// catch-all matches any remaining segments
|
|
68
|
+
return pathSegments.length >= catchAllIdx
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// for non-catch-all, segment count should match
|
|
72
|
+
if (routeSegments.length !== pathSegments.length) return false
|
|
73
|
+
|
|
74
|
+
for (let i = 0; i < routeSegments.length; i++) {
|
|
75
|
+
const routeSeg = routeSegments[i]
|
|
76
|
+
const pathSeg = pathSegments[i]
|
|
77
|
+
|
|
78
|
+
// dynamic segment [param] matches any value
|
|
79
|
+
if (routeSeg.startsWith('[') && routeSeg.endsWith(']')) {
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// static segment must match exactly
|
|
84
|
+
if (routeSeg !== pathSeg) return false
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Preloads route modules for a given URL path (production only).
|
|
92
|
+
* This ensures route components are loaded before navigation completes,
|
|
93
|
+
* preventing Suspense boundaries from triggering and causing flicker.
|
|
94
|
+
*
|
|
95
|
+
* Called during `linkTo()` to preload routes before client-side navigation.
|
|
96
|
+
*/
|
|
97
|
+
export async function preloadRouteModules(href: string): Promise<void> {
|
|
98
|
+
const globbed = globalThis['__importMetaGlobbed']
|
|
99
|
+
if (!globbed) return
|
|
100
|
+
|
|
101
|
+
// normalize href to match route keys - /docs -> docs
|
|
102
|
+
const normalizedHref = href === '/' ? '' : href.replace(/^\//, '').replace(/\/$/, '')
|
|
103
|
+
|
|
104
|
+
const promises: Promise<any>[] = []
|
|
105
|
+
|
|
106
|
+
for (const key of Object.keys(globbed)) {
|
|
107
|
+
// key looks like "/app/(site)/docs/_layout.tsx" or "/app/(site)/docs/index+ssg.tsx"
|
|
108
|
+
// strip the /app/ prefix first
|
|
109
|
+
let routePath = key.replace(/^\/[^/]+\//, '')
|
|
110
|
+
|
|
111
|
+
// strip route groups like (site), (app) etc
|
|
112
|
+
routePath = routePath.replace(/\([^)]+\)\//g, '')
|
|
113
|
+
|
|
114
|
+
// strip file suffixes but keep the path structure
|
|
115
|
+
routePath = routePath
|
|
116
|
+
.replace(/\/_layout\.tsx$/, '')
|
|
117
|
+
.replace(/\/index(\+[a-z]+)?\.tsx$/, '')
|
|
118
|
+
.replace(/(\+[a-z]+)?\.tsx$/, '')
|
|
119
|
+
|
|
120
|
+
// remove leading slash if any
|
|
121
|
+
routePath = routePath.replace(/^\//, '')
|
|
122
|
+
|
|
123
|
+
// check if this route is part of the target path
|
|
124
|
+
const isStaticMatch =
|
|
125
|
+
routePath === normalizedHref || // exact match
|
|
126
|
+
routePath.startsWith(normalizedHref + '/') || // child route
|
|
127
|
+
normalizedHref.startsWith(routePath + '/') || // parent layout
|
|
128
|
+
routePath === '' || // root layout
|
|
129
|
+
(normalizedHref !== '' && routePath === normalizedHref.split('/')[0]) // top-level match
|
|
130
|
+
|
|
131
|
+
// also check dynamic route patterns like docs/[slug]
|
|
132
|
+
const isDynamicMatch = routePath.includes('[') && matchDynamicRoute(routePath, normalizedHref)
|
|
133
|
+
|
|
134
|
+
if ((isStaticMatch || isDynamicMatch) && typeof globbed[key] === 'function') {
|
|
135
|
+
promises.push(
|
|
136
|
+
globbed[key]()
|
|
137
|
+
.then((mod: any) => {
|
|
138
|
+
preloadedModules[key] = mod
|
|
139
|
+
})
|
|
140
|
+
.catch(() => {})
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await Promise.all(promises)
|
|
146
|
+
}
|
|
147
|
+
|
|
29
148
|
export function loadRoutes(
|
|
30
149
|
paths: GlobbedRouteImports,
|
|
31
150
|
routerRoot: string,
|
|
@@ -77,6 +196,14 @@ export function globbedRoutesToRouteContext(
|
|
|
77
196
|
return loadedRoutes[id]
|
|
78
197
|
}
|
|
79
198
|
|
|
199
|
+
// check if this route was preloaded (via preload file or hydration)
|
|
200
|
+
const preloadKey = id.replace('./', `/${routerRoot}/`)
|
|
201
|
+
const preloaded = getPreloadedModule(preloadKey)
|
|
202
|
+
if (preloaded) {
|
|
203
|
+
loadedRoutes[id] = preloaded
|
|
204
|
+
return preloaded
|
|
205
|
+
}
|
|
206
|
+
|
|
80
207
|
if (typeof routesSync[id] !== 'function') {
|
|
81
208
|
return routesSync[id]
|
|
82
209
|
}
|
|
@@ -98,23 +225,6 @@ export function globbedRoutesToRouteContext(
|
|
|
98
225
|
console.error(`Error loading route`, id, err, new Error().stack)
|
|
99
226
|
loadedRoutes[id] = {
|
|
100
227
|
default: () => null,
|
|
101
|
-
// <View
|
|
102
|
-
// style={{
|
|
103
|
-
// position: 'absolute',
|
|
104
|
-
// top: 0,
|
|
105
|
-
// left: 0,
|
|
106
|
-
// right: 0,
|
|
107
|
-
// bottom: 0,
|
|
108
|
-
// alignItems: 'center',
|
|
109
|
-
// justifyContent: 'center',
|
|
110
|
-
// backgroundColor: '#000',
|
|
111
|
-
// gap: 20,
|
|
112
|
-
// }}
|
|
113
|
-
// >
|
|
114
|
-
// <Text style={{ fontSize: 24, color: '#fff' }}>Error loading route</Text>
|
|
115
|
-
// <Text style={{ fontSize: 16, color: '#fff' }}>{id}</Text>
|
|
116
|
-
// <Text style={{ fontSize: 18, color: '#fff', maxWidth: 800 }}>{`${err}`}</Text>
|
|
117
|
-
// </View>
|
|
118
228
|
}
|
|
119
229
|
delete promises[id]
|
|
120
230
|
})
|
|
@@ -39,14 +39,15 @@ export function getNavigateAction(
|
|
|
39
39
|
const childState = actionStateRoute.state
|
|
40
40
|
const nextNavigationState = stateRoute.state
|
|
41
41
|
|
|
42
|
-
const
|
|
42
|
+
const dynamicMatch = matchDynamicName(actionStateRoute.name)
|
|
43
43
|
|
|
44
44
|
const didActionAndCurrentStateDiverge =
|
|
45
45
|
actionStateRoute.name !== stateRoute.name ||
|
|
46
46
|
// !deepEqual(actionStateRoute.params, stateRoute.params) ||
|
|
47
47
|
!childState ||
|
|
48
48
|
!nextNavigationState ||
|
|
49
|
-
(
|
|
49
|
+
(dynamicMatch &&
|
|
50
|
+
actionStateRoute.params?.[dynamicMatch.name] !== stateRoute.params?.[dynamicMatch.name])
|
|
50
51
|
|
|
51
52
|
if (didActionAndCurrentStateDiverge) {
|
|
52
53
|
break
|
package/src/server/oneServe.ts
CHANGED
|
@@ -18,6 +18,8 @@ import { toAbsolute } from '../utils/toAbsolute'
|
|
|
18
18
|
import type { One } from '../vite/types'
|
|
19
19
|
import type { RouteInfoCompiled } from './createRoutesManifest'
|
|
20
20
|
|
|
21
|
+
const debugRouter = process.env.ONE_DEBUG_ROUTER
|
|
22
|
+
|
|
21
23
|
export async function oneServe(oneOptions: One.PluginOptions, buildInfo: One.BuildInfo, app: Hono) {
|
|
22
24
|
const { resolveAPIRoute, resolveLoaderRoute, resolvePageRoute } = await import(
|
|
23
25
|
'../createHandleRequest'
|
|
@@ -36,6 +38,9 @@ export async function oneServe(oneOptions: One.PluginOptions, buildInfo: One.Bui
|
|
|
36
38
|
const paramName = param.substring(1)
|
|
37
39
|
return context.req.param(paramName) || ''
|
|
38
40
|
})
|
|
41
|
+
if (debugRouter) {
|
|
42
|
+
console.info(`[one] ↪ redirect ${context.req.path} → ${destinationUrl}`)
|
|
43
|
+
}
|
|
39
44
|
return context.redirect(destinationUrl, redirect.permanent ? 301 : 302)
|
|
40
45
|
})
|
|
41
46
|
}
|
|
@@ -180,11 +185,19 @@ url: ${url}`)
|
|
|
180
185
|
|
|
181
186
|
switch (route.type) {
|
|
182
187
|
case 'api': {
|
|
188
|
+
if (debugRouter) {
|
|
189
|
+
console.info(`[one] ⚡ ${url.pathname} → matched API route: ${route.page}`)
|
|
190
|
+
}
|
|
183
191
|
return resolveAPIRoute(requestHandlers, request, url, route)
|
|
184
192
|
}
|
|
185
193
|
case 'ssg':
|
|
186
194
|
case 'spa':
|
|
187
195
|
case 'ssr': {
|
|
196
|
+
if (debugRouter) {
|
|
197
|
+
console.info(
|
|
198
|
+
`[one] ⚡ ${url.pathname} → matched page route: ${route.page} (${route.type})`
|
|
199
|
+
)
|
|
200
|
+
}
|
|
188
201
|
return resolvePageRoute(requestHandlers, request, url, route)
|
|
189
202
|
}
|
|
190
203
|
}
|
package/src/types.ts
CHANGED
package/src/useLoader.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useCallback, useSyncExternalStore } from 'react'
|
|
2
2
|
import { useParams, usePathname } from './hooks'
|
|
3
|
-
import {
|
|
4
|
-
import { preloadingLoader } from './router/router'
|
|
3
|
+
import { preloadedLoaderData, preloadingLoader } from './router/router'
|
|
5
4
|
import { getLoaderPath } from './utils/cleanUrl'
|
|
6
5
|
import { dynamicImport } from './utils/dynamicImport'
|
|
7
6
|
import { weakKey } from './utils/weakKey'
|
|
@@ -89,7 +88,9 @@ export function useLoaderState<
|
|
|
89
88
|
|
|
90
89
|
const params = useParams()
|
|
91
90
|
const pathname = usePathname()
|
|
92
|
-
|
|
91
|
+
// use just the pathname for matching, don't use resolveHref which adds params as query string
|
|
92
|
+
// (the pathname is already resolved like /docs/getting-started, not /docs/[slug])
|
|
93
|
+
const currentPath = pathname.replace(/\/index$/, '').replace(/\/$/, '') || '/'
|
|
93
94
|
|
|
94
95
|
// server-side
|
|
95
96
|
if (typeof window === 'undefined' && loader) {
|
|
@@ -103,9 +104,9 @@ export function useLoaderState<
|
|
|
103
104
|
return { data: serverData, refetch: async () => {}, state: 'idle' } as any
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
// preloaded data from SSR
|
|
107
|
-
const
|
|
108
|
-
|
|
107
|
+
// preloaded data from SSR/SSG - only use if server context path matches current path
|
|
108
|
+
const serverContextPath = loaderPropsFromServerContext?.path
|
|
109
|
+
const preloadedData = serverContextPath === currentPath ? loaderDataFromServerContext : undefined
|
|
109
110
|
|
|
110
111
|
const loaderStateEntry = useSyncExternalStore(
|
|
111
112
|
subscribe,
|
|
@@ -130,14 +131,21 @@ export function useLoaderState<
|
|
|
130
131
|
!loaderStateEntry.hasLoadedOnce &&
|
|
131
132
|
loader
|
|
132
133
|
) {
|
|
133
|
-
// check for
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
// check for already-resolved preloaded data first (synchronous)
|
|
135
|
+
const resolvedPreloadData = preloadedLoaderData[currentPath]
|
|
136
|
+
if (resolvedPreloadData !== undefined) {
|
|
137
|
+
// Data was preloaded and already resolved - use it directly
|
|
138
|
+
delete preloadedLoaderData[currentPath]
|
|
139
|
+
delete preloadingLoader[currentPath]
|
|
140
|
+
loaderStateEntry.data = resolvedPreloadData
|
|
141
|
+
loaderStateEntry.hasLoadedOnce = true
|
|
142
|
+
} else if (preloadingLoader[currentPath]) {
|
|
143
|
+
// Preload is in progress - wait for it
|
|
144
|
+
const preloadPromise = preloadingLoader[currentPath]!
|
|
145
|
+
const promise = preloadPromise
|
|
139
146
|
.then((val: any) => {
|
|
140
147
|
delete preloadingLoader[currentPath]
|
|
148
|
+
delete preloadedLoaderData[currentPath]
|
|
141
149
|
updateState(currentPath, {
|
|
142
150
|
data: val,
|
|
143
151
|
hasLoadedOnce: true,
|
package/src/vite/one.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import events from 'node:events'
|
|
2
|
-
import path from 'node:path'
|
|
3
1
|
import { configureVXRNCompilerPlugin } from '@vxrn/compiler'
|
|
4
2
|
import { resolvePath } from '@vxrn/resolve'
|
|
5
3
|
import type {
|
|
6
4
|
ExpoManifestRequestHandlerPluginPluginOptions,
|
|
7
5
|
MetroPluginOptions,
|
|
8
6
|
} from '@vxrn/vite-plugin-metro'
|
|
7
|
+
import events from 'node:events'
|
|
8
|
+
import path from 'node:path'
|
|
9
9
|
import type { Plugin, PluginOption } from 'vite'
|
|
10
10
|
import { barrel } from 'vite-plugin-barrel'
|
|
11
11
|
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
12
|
-
import { autoDepOptimizePlugin,
|
|
12
|
+
import { autoDepOptimizePlugin, getOptionsFilled, loadEnv } from 'vxrn'
|
|
13
13
|
import vxrnVitePlugin from 'vxrn/vite-plugin'
|
|
14
14
|
import { CACHE_KEY } from '../constants'
|
|
15
15
|
import { getViteMetroPluginOptions } from '../metro-config/getViteMetroPluginOptions'
|
|
@@ -121,15 +121,6 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
|
121
121
|
void ensureTSConfig()
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
// build is superset for now
|
|
125
|
-
const { optimizeDeps } = getOptimizeDeps('build')
|
|
126
|
-
const optimizeIds = optimizeDeps.include
|
|
127
|
-
const optimizeIdRegex = new RegExp(
|
|
128
|
-
// santize ids for regex
|
|
129
|
-
// https://stackoverflow.com/questions/6300183/sanitize-string-of-regex-characters-before-regexp-build
|
|
130
|
-
`${optimizeIds.map((id) => id.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&')).join('|')}`
|
|
131
|
-
)
|
|
132
|
-
|
|
133
124
|
let tsConfigPathsPlugin: Plugin | null = null
|
|
134
125
|
|
|
135
126
|
const vxrnOptions = getOptionsFilled()
|
|
@@ -167,7 +158,12 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
|
167
158
|
userConfig?.envPrefix
|
|
168
159
|
)
|
|
169
160
|
return {
|
|
170
|
-
define:
|
|
161
|
+
define: {
|
|
162
|
+
...clientEnvDefine,
|
|
163
|
+
...(process.env.ONE_DEBUG_ROUTER && {
|
|
164
|
+
'process.env.ONE_DEBUG_ROUTER': JSON.stringify(process.env.ONE_DEBUG_ROUTER),
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
171
167
|
}
|
|
172
168
|
},
|
|
173
169
|
},
|
|
@@ -17,6 +17,8 @@ import type { One } from '../../vite/types'
|
|
|
17
17
|
import { setServerContext } from '../one-server-only'
|
|
18
18
|
import { virtalEntryIdClient, virtualEntryId } from './virtualEntryConstants'
|
|
19
19
|
|
|
20
|
+
const debugRouter = process.env.ONE_DEBUG_ROUTER
|
|
21
|
+
|
|
20
22
|
// server needs better dep optimization
|
|
21
23
|
const USE_SERVER_ENV = false //!!process.env.USE_SERVER_ENV
|
|
22
24
|
|
|
@@ -329,7 +331,9 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
|
329
331
|
})
|
|
330
332
|
}
|
|
331
333
|
|
|
332
|
-
|
|
334
|
+
if (debugRouter) {
|
|
335
|
+
console.info(`[one] ↪ redirect ${url.pathname} → ${destination}`)
|
|
336
|
+
}
|
|
333
337
|
|
|
334
338
|
res.writeHead(redirect.permanent ? 301 : 302, { Location: destination })
|
|
335
339
|
res.end()
|
|
@@ -338,13 +342,21 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
|
338
342
|
}
|
|
339
343
|
}
|
|
340
344
|
|
|
341
|
-
const reply = await handleRequest.handler(
|
|
345
|
+
const reply = await handleRequest.handler(convertIncomingMessageToRequest(req))
|
|
342
346
|
|
|
343
347
|
if (!reply) {
|
|
344
348
|
return next()
|
|
345
349
|
}
|
|
346
350
|
|
|
347
351
|
if (typeof reply !== 'string' && isResponse(reply)) {
|
|
352
|
+
if (debugRouter) {
|
|
353
|
+
const headers: Record<string, string> = {}
|
|
354
|
+
reply.headers.forEach((v, k) => {
|
|
355
|
+
headers[k] = v
|
|
356
|
+
})
|
|
357
|
+
console.info(`[one] 📤 response ${reply.status}`, headers)
|
|
358
|
+
}
|
|
359
|
+
|
|
348
360
|
reply.headers.forEach((value, key) => {
|
|
349
361
|
if (key === 'set-cookie') {
|
|
350
362
|
// for some reason it wasnt doing working without this?
|
|
@@ -359,7 +371,9 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
|
359
371
|
|
|
360
372
|
if (isStatusRedirect(reply.status)) {
|
|
361
373
|
const location = `${reply.headers.get('location') || ''}`
|
|
362
|
-
|
|
374
|
+
if (debugRouter) {
|
|
375
|
+
console.info(`[one] ↪ response redirect → ${location}`)
|
|
376
|
+
}
|
|
363
377
|
if (location) {
|
|
364
378
|
res.writeHead(reply.status, {
|
|
365
379
|
Location: location,
|
|
@@ -373,8 +387,6 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
|
373
387
|
res.statusCode = reply.status
|
|
374
388
|
res.statusMessage = reply.statusText
|
|
375
389
|
|
|
376
|
-
let outString = ''
|
|
377
|
-
|
|
378
390
|
if (reply.body) {
|
|
379
391
|
if (reply.body.locked) {
|
|
380
392
|
console.warn(`Body is locked??`, req.url)
|