one 1.2.20 → 1.2.21
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/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 +26 -19
- package/dist/cjs/fork/useLinking.js +31 -19
- 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/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 +6 -6
- package/dist/cjs/router/router.js +6 -6
- package/dist/cjs/router/router.js.map +1 -1
- package/dist/cjs/router/router.native.js +6 -6
- package/dist/cjs/router/router.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/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/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 +31 -18
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +26 -19
- 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/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 +6 -6
- package/dist/esm/router/router.js.map +1 -1
- package/dist/esm/router/router.mjs +6 -6
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +6 -6
- package/dist/esm/router/router.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/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/package.json +9 -9
- 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 +80 -5
- package/src/getReactNavigationConfig.ts +7 -9
- package/src/hooks.tsx +21 -19
- 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 +6 -6
- package/src/router/utils/getNavigateAction.ts +3 -2
- package/src/server/oneServe.ts +13 -0
- package/src/vite/one.ts +9 -13
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +17 -5
- 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/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/utils/getNavigateAction.d.ts.map +1 -1
- package/types/server/oneServe.d.ts.map +1 -1
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
|
@@ -20,7 +20,8 @@ function _type_of(obj) {
|
|
|
20
20
|
|
|
21
21
|
return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
22
22
|
}
|
|
23
|
-
var
|
|
23
|
+
var debugRouter = process.env.ONE_DEBUG_ROUTER,
|
|
24
|
+
USE_SERVER_ENV = !1;
|
|
24
25
|
//!!process.env.USE_SERVER_ENV
|
|
25
26
|
function createFileSystemRouterPlugin(options) {
|
|
26
27
|
var preloads = ["/@vite/client", virtalEntryIdClient],
|
|
@@ -252,7 +253,7 @@ ${stack}
|
|
|
252
253
|
params = redirect.source.match(/:\w+/g);
|
|
253
254
|
return params && params.forEach(function (param2, index) {
|
|
254
255
|
destination = destination.replace(param2, match[index + 1] || "");
|
|
255
|
-
}), console.
|
|
256
|
+
}), debugRouter && console.info(`[one] \u21AA redirect ${url2.pathname} \u2192 ${destination}`), res.writeHead(redirect.permanent ? 301 : 302, {
|
|
256
257
|
Location: destination
|
|
257
258
|
}), res.end(), {
|
|
258
259
|
v: void 0
|
|
@@ -272,9 +273,15 @@ ${stack}
|
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
275
|
}
|
|
275
|
-
var reply = await handleRequest.handler(
|
|
276
|
+
var reply = await handleRequest.handler(convertIncomingMessageToRequest(req));
|
|
276
277
|
if (!reply) return next();
|
|
277
278
|
if (typeof reply != "string" && isResponse(reply)) {
|
|
279
|
+
if (debugRouter) {
|
|
280
|
+
var headers = {};
|
|
281
|
+
reply.headers.forEach(function (v, k) {
|
|
282
|
+
headers[k] = v;
|
|
283
|
+
}), console.info(`[one] \u{1F4E4} response ${reply.status}`, headers);
|
|
284
|
+
}
|
|
278
285
|
if (reply.headers.forEach(function (value, key) {
|
|
279
286
|
if (key === "set-cookie") {
|
|
280
287
|
var cookies = value.split(", "),
|
|
@@ -298,7 +305,7 @@ ${stack}
|
|
|
298
305
|
} else res.setHeader(key, value);
|
|
299
306
|
}), isStatusRedirect(reply.status)) {
|
|
300
307
|
var location = `${reply.headers.get("location") || ""}`;
|
|
301
|
-
if (console.info(` \
|
|
308
|
+
if (debugRouter && console.info(`[one] \u21AA response redirect \u2192 ${location}`), location) {
|
|
302
309
|
res.writeHead(reply.status, {
|
|
303
310
|
Location: location
|
|
304
311
|
}), res.end();
|
|
@@ -306,9 +313,7 @@ ${stack}
|
|
|
306
313
|
}
|
|
307
314
|
console.error("No location provided to redirected status reply", reply);
|
|
308
315
|
}
|
|
309
|
-
res.statusCode = reply.status, res.statusMessage = reply.statusText
|
|
310
|
-
var outString = "";
|
|
311
|
-
if (reply.body && reply.body.locked) {
|
|
316
|
+
if (res.statusCode = reply.status, res.statusMessage = reply.statusText, reply.body && reply.body.locked) {
|
|
312
317
|
console.warn("Body is locked??", req.url), res.write(""), res.end();
|
|
313
318
|
return;
|
|
314
319
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["join","Readable","debounce","createServerModuleRunner","getSpaHeaderElements","createHandleRequest","getRouterRootFromOneOptions","isResponse","isStatusRedirect","promiseWithResolvers","LoaderDataCache","replaceLoader","setServerContext","virtalEntryIdClient","virtualEntryId","_instanceof","left","right","Symbol","hasInstance","_type_of","obj","constructor","USE_SERVER_ENV","createFileSystemRouterPlugin","options","preloads","runner","server","handleRequest","createRequestHandler","renderPromise","routerRoot","handlePage","param","route","url","loaderProps","console","info","type","isNotFound","file","slice","serverContext","mode","promise","resolve","_globalThis___vxrnresetState","_globalThis","_exported_loader","routeFile","clearCache","globalThis","__vxrnresetState","call","exported","import","loaderData","loader","eval","entry","render","default","is404","html","path","Response","status","headers","err","error","href","title","pathname","message","Error","stack","isDuplicateReactError","test","subMessage","handleLoader","param2","request","route2","url2","loaderProps2","_this","_exported_loader2","routeFile2","transformedJS","transformRequest","code","exported2","loaderData2","platform","searchParams","get","environment","environments","nativeTransformedJS","JSON","stringify","handleAPI","loadMiddleware","contextKey","name","enforce","apply","config","userConfig","_options_optimization","_options_optimization_autoEntriesScanning","setting","optimization","autoEntriesScanning","manifest","pageRoutes","routesAndLayouts","Set","flatMap","_route_layouts","split","filter","x","startsWith","length","layouts","layout","optimizeDeps","entries","configureServer","serverIn","ssr","appDir","
|
|
1
|
+
{"version":3,"names":["join","Readable","debounce","createServerModuleRunner","getSpaHeaderElements","createHandleRequest","getRouterRootFromOneOptions","isResponse","isStatusRedirect","promiseWithResolvers","LoaderDataCache","replaceLoader","setServerContext","virtalEntryIdClient","virtualEntryId","_instanceof","left","right","Symbol","hasInstance","_type_of","obj","constructor","debugRouter","process","env","ONE_DEBUG_ROUTER","USE_SERVER_ENV","createFileSystemRouterPlugin","options","preloads","runner","server","handleRequest","createRequestHandler","renderPromise","routerRoot","handlePage","param","route","url","loaderProps","console","info","type","isNotFound","file","slice","serverContext","mode","promise","resolve","_globalThis___vxrnresetState","_globalThis","_exported_loader","routeFile","clearCache","globalThis","__vxrnresetState","call","exported","import","loaderData","loader","eval","entry","render","default","is404","html","path","Response","status","headers","err","error","href","title","pathname","message","Error","stack","isDuplicateReactError","test","subMessage","handleLoader","param2","request","route2","url2","loaderProps2","_this","_exported_loader2","routeFile2","transformedJS","transformRequest","code","exported2","loaderData2","platform","searchParams","get","environment","environments","nativeTransformedJS","JSON","stringify","handleAPI","loadMiddleware","contextKey","name","enforce","apply","config","userConfig","_options_optimization","_options_optimization_autoEntriesScanning","setting","optimization","autoEntriesScanning","manifest","pageRoutes","routesAndLayouts","Set","flatMap","_route_layouts","split","filter","x","startsWith","length","layouts","layout","optimizeDeps","entries","configureServer","serverIn","ssr","appDir","cwd","fileWatcherChangeListener","watcher","addListener","middlewares","use","req","res","next","_options_web","redirects","web","URL","host","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_loop","redirect","_step","value","regexStr","source","replace","match","RegExp","destination","params","forEach","index","writeHead","permanent","Location","end","v","_iterator","iterator","done","_ret","return","reply","handler","convertIncomingMessageToRequest"],"sources":["../../../../src/vite/plugins/fileSystemRouterPlugin.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAA,QAAY;AACrB,SAASC,QAAA,QAAgB;AACzB,SAASC,QAAA,QAAgB;AAEzB,SAASC,wBAAA,QAAgC;AAEzC,SAASC,oBAAA,QAA4B;AACrC,SAASC,mBAAA,QAA2B;AAEpC,SAASC,2BAAA,QAAmC;AAC5C,SAASC,UAAA,QAAkB;AAC3B,SAASC,gBAAA,QAAwB;AACjC,SAASC,oBAAA,QAA4B;AACrC,SAASC,eAAA,QAAuB;AAChC,SAASC,aAAA,QAAqB;AAE9B,SAASC,gBAAA,QAAwB;AACjC,SAASC,mBAAA,EAAqBC,cAAA,QAAsB;AAEpD,SAAMC,WAAcA,CAAAC,IAAA,EAAAC,KAAY;EAGH,OAAAA,KAAA,mBAAAC,MAAA,UAAAD,KAAA,CAAAC,MAAA,CAAAC,WAAA,MAAAF,KAAA,CAAAC,MAAA,CAAAC,WAAA,EAAAH,IAAA,IAAAA,IAAA,YAAAC,KAAA;AAEtB;AACL,SAAMG,SAAAC,GAAY;EAElB,uBAGI;;EAIJ,OAAAA,GAAS,WAAAH,MAAA,MAAuB,IAAAG,GAAA,CAAAC,WAAA,KAAAJ,MAAA,qBAAAG,GAAA;AAC9B;AACA,IAAAE,WAAO,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AAAJ,SAAA,CAAAI,MAAA;gBAIjC,UAAQ;kBAGd,IAAQxB,iBAAK,EACV,MAAAC,cAAA;gBACZ;cACA;YAAA;YAEQ,IAAAwB,KAAA,SAAAlJ,aAAA,CAAAmJ,OAAA,CAAAC,+BAAA,CAAApC,GAAA;YAC2B,KAAAkC,KAAA,EACvC,OAAAhC,IAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "one",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.21",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"setup.mjs",
|
|
@@ -121,17 +121,17 @@
|
|
|
121
121
|
"@react-navigation/routers": "~7.5.1",
|
|
122
122
|
"@swc/core": "^1.14.0",
|
|
123
123
|
"@ungap/structured-clone": "^1.2.0",
|
|
124
|
-
"@vxrn/compiler": "1.2.
|
|
125
|
-
"@vxrn/resolve": "1.2.
|
|
126
|
-
"@vxrn/tslib-lite": "1.2.
|
|
127
|
-
"@vxrn/universal-color-scheme": "1.2.
|
|
128
|
-
"@vxrn/use-isomorphic-layout-effect": "1.2.
|
|
129
|
-
"@vxrn/vite-plugin-metro": "1.2.
|
|
124
|
+
"@vxrn/compiler": "1.2.21",
|
|
125
|
+
"@vxrn/resolve": "1.2.21",
|
|
126
|
+
"@vxrn/tslib-lite": "1.2.21",
|
|
127
|
+
"@vxrn/universal-color-scheme": "1.2.21",
|
|
128
|
+
"@vxrn/use-isomorphic-layout-effect": "1.2.21",
|
|
129
|
+
"@vxrn/vite-plugin-metro": "1.2.21",
|
|
130
130
|
"babel-dead-code-elimination": "^1.0.10",
|
|
131
131
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
132
132
|
"citty": "^0.1.6",
|
|
133
133
|
"core-js": "^3.38.1",
|
|
134
|
-
"create-vxrn": "1.2.
|
|
134
|
+
"create-vxrn": "1.2.21",
|
|
135
135
|
"escape-string-regexp": "^5.0.0",
|
|
136
136
|
"expo-linking": "~8.0.8",
|
|
137
137
|
"expo-modules-core": "~3.0.24",
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
"vite": "^7.1.12",
|
|
158
158
|
"vite-plugin-barrel": "^0.4.1",
|
|
159
159
|
"vite-tsconfig-paths": "^5.1.4",
|
|
160
|
-
"vxrn": "1.2.
|
|
160
|
+
"vxrn": "1.2.21",
|
|
161
161
|
"ws": "^8.18.0",
|
|
162
162
|
"xxhashjs": "^0.2.2"
|
|
163
163
|
},
|
|
@@ -25,6 +25,8 @@ type RequestHandlerProps<RouteExtraProps extends Object = {}> = {
|
|
|
25
25
|
|
|
26
26
|
type RequestHandlerResponse = null | string | Response
|
|
27
27
|
|
|
28
|
+
const debugRouter = process.env.ONE_DEBUG_ROUTER
|
|
29
|
+
|
|
28
30
|
export async function runMiddlewares(
|
|
29
31
|
handlers: RequestHandlers,
|
|
30
32
|
request: Request,
|
|
@@ -40,6 +42,10 @@ export async function runMiddlewares(
|
|
|
40
42
|
throw new Error(`No middleware handler configured`)
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
if (debugRouter) {
|
|
46
|
+
console.info(`[one] 🔗 middleware chain (${middlewares.length}) for ${route.page}`)
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
const context: MiddlewareContext = {}
|
|
44
50
|
|
|
45
51
|
async function dispatch(index: number): Promise<Response> {
|
|
@@ -47,9 +53,16 @@ export async function runMiddlewares(
|
|
|
47
53
|
|
|
48
54
|
// no more middlewares, finish
|
|
49
55
|
if (!middlewareModule) {
|
|
56
|
+
if (debugRouter) {
|
|
57
|
+
console.info(`[one] ✓ middleware chain complete`)
|
|
58
|
+
}
|
|
50
59
|
return await getResponse()
|
|
51
60
|
}
|
|
52
61
|
|
|
62
|
+
if (debugRouter) {
|
|
63
|
+
console.info(`[one] → middleware[${index}]: ${middlewareModule.contextKey}`)
|
|
64
|
+
}
|
|
65
|
+
|
|
53
66
|
const exported = (await handlers.loadMiddleware!(middlewareModule))?.default as
|
|
54
67
|
| Middleware
|
|
55
68
|
| undefined
|
|
@@ -67,6 +80,9 @@ export async function runMiddlewares(
|
|
|
67
80
|
const response = await exported({ request, next, context })
|
|
68
81
|
|
|
69
82
|
if (response) {
|
|
83
|
+
if (debugRouter) {
|
|
84
|
+
console.info(`[one] ← middleware[${index}] returned early (status: ${response.status})`)
|
|
85
|
+
}
|
|
70
86
|
return response
|
|
71
87
|
}
|
|
72
88
|
|
|
@@ -87,6 +103,10 @@ export async function resolveAPIRoute(
|
|
|
87
103
|
const { pathname } = url
|
|
88
104
|
const params = getRouteParams(pathname, route)
|
|
89
105
|
|
|
106
|
+
if (debugRouter) {
|
|
107
|
+
console.info(`[one] 📡 API ${request.method} ${pathname} → ${route.file}`, params)
|
|
108
|
+
}
|
|
109
|
+
|
|
90
110
|
try {
|
|
91
111
|
return resolveAPIEndpoint(
|
|
92
112
|
() =>
|
|
@@ -128,6 +148,10 @@ export async function resolveLoaderRoute(
|
|
|
128
148
|
url: URL,
|
|
129
149
|
route: RouteInfoCompiled
|
|
130
150
|
) {
|
|
151
|
+
if (debugRouter) {
|
|
152
|
+
console.info(`[one] 📦 loader ${url.pathname} → ${route.file}`)
|
|
153
|
+
}
|
|
154
|
+
|
|
131
155
|
return await runMiddlewares(handlers, request, route, async () => {
|
|
132
156
|
return await resolveResponse(async () => {
|
|
133
157
|
const headers = new Headers()
|
|
@@ -171,6 +195,10 @@ export async function resolvePageRoute(
|
|
|
171
195
|
) {
|
|
172
196
|
const { pathname, search } = url
|
|
173
197
|
|
|
198
|
+
if (debugRouter) {
|
|
199
|
+
console.info(`[one] 📄 page ${pathname} → ${route.file} (${route.type})`)
|
|
200
|
+
}
|
|
201
|
+
|
|
174
202
|
return resolveResponse(async () => {
|
|
175
203
|
const resolved = await runMiddlewares(handlers, request, route, async () => {
|
|
176
204
|
return await handlers.handlePage!({
|
|
@@ -241,6 +269,9 @@ export function createHandleRequest(
|
|
|
241
269
|
return route.compiledRegex.test(pathname)
|
|
242
270
|
})
|
|
243
271
|
if (apiRoute) {
|
|
272
|
+
if (debugRouter) {
|
|
273
|
+
console.info(`[one] ⚡ ${pathname} → matched API route: ${apiRoute.page}`)
|
|
274
|
+
}
|
|
244
275
|
return await resolveAPIRoute(handlers, request, url, apiRoute)
|
|
245
276
|
}
|
|
246
277
|
}
|
|
@@ -291,6 +322,9 @@ export function createHandleRequest(
|
|
|
291
322
|
if (!route.compiledRegex.test(pathname)) {
|
|
292
323
|
continue
|
|
293
324
|
}
|
|
325
|
+
if (debugRouter) {
|
|
326
|
+
console.info(`[one] ⚡ ${pathname} → matched page route: ${route.page} (${route.type})`)
|
|
327
|
+
}
|
|
294
328
|
return resolvePageRoute(handlers, request, url, route)
|
|
295
329
|
}
|
|
296
330
|
}
|
|
@@ -164,6 +164,14 @@ function NavigationContainerInner(
|
|
|
164
164
|
|
|
165
165
|
const [isResolved, initialState] = useThenable(getInitialState)
|
|
166
166
|
|
|
167
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
168
|
+
console.info(
|
|
169
|
+
`[one] 🏠 NavigationContainer isResolved=${isResolved} initialState=`,
|
|
170
|
+
JSON.stringify(initialState, null, 2)
|
|
171
|
+
)
|
|
172
|
+
console.info(`[one] 🏠 NavigationContainer rest.initialState=`, rest.initialState)
|
|
173
|
+
}
|
|
174
|
+
|
|
167
175
|
React.useImperativeHandle(ref, () => refContainer.current!)
|
|
168
176
|
|
|
169
177
|
const isLinkingReady = rest.initialState != null || !isLinkingEnabled || isResolved
|
|
@@ -82,6 +82,10 @@ export function createMemoryHistory() {
|
|
|
82
82
|
items.push({ path, state, id })
|
|
83
83
|
index = items.length - 1
|
|
84
84
|
|
|
85
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
86
|
+
console.info(`[one] 📜 history.push path=${path}`)
|
|
87
|
+
}
|
|
88
|
+
|
|
85
89
|
// We pass empty string for title because it's ignored in all browsers except safari
|
|
86
90
|
// We don't store state object in history.state because:
|
|
87
91
|
// - browsers have limits on how big it can be, and we don't control the size
|
|
@@ -117,6 +121,10 @@ export function createMemoryHistory() {
|
|
|
117
121
|
items[index] = { path, state, id }
|
|
118
122
|
}
|
|
119
123
|
|
|
124
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
125
|
+
console.info(`[one] 📜 history.replace path=${pathWithHash}`)
|
|
126
|
+
}
|
|
127
|
+
|
|
120
128
|
window.history.replaceState({ id }, '', pathWithHash)
|
|
121
129
|
},
|
|
122
130
|
|
|
@@ -82,6 +82,12 @@ function fromDeepLink(url: string): string {
|
|
|
82
82
|
* - It has a valid App scheme, but the scheme isn't a valid URL scheme (e.g. `my_app://`)
|
|
83
83
|
*/
|
|
84
84
|
|
|
85
|
+
// If `url` is already a path (starts with `/`), return it as-is
|
|
86
|
+
// This prevents incorrect rewrites when URL is in query params (e.g. `/?url=https://example.com`)
|
|
87
|
+
if (url.startsWith('/')) {
|
|
88
|
+
return url
|
|
89
|
+
}
|
|
90
|
+
|
|
85
91
|
/**
|
|
86
92
|
* App schemes are not valid URL schemes, so they will fail to parse.
|
|
87
93
|
* We need to strip the scheme from these URLs
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import type { Route } from '@react-navigation/core'
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { matchDynamicName, matchGroupName } from '../router/matchers'
|
|
10
10
|
import { getParamName } from './_shared'
|
|
11
11
|
|
|
12
12
|
export type AdditionalOptions = {
|
|
@@ -136,12 +136,7 @@ export function appendBaseUrl(
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
function segmentMatchesConvention(segment: string): boolean {
|
|
139
|
-
return (
|
|
140
|
-
segment === 'index' ||
|
|
141
|
-
matchDynamicName(segment) != null ||
|
|
142
|
-
matchGroupName(segment) != null ||
|
|
143
|
-
matchDeepDynamicRouteName(segment) != null
|
|
144
|
-
)
|
|
139
|
+
return segment === 'index' || matchDynamicName(segment) != null || matchGroupName(segment) != null
|
|
145
140
|
}
|
|
146
141
|
|
|
147
142
|
function encodeURISegment(str: string, { preserveBrackets = false } = {}) {
|
|
@@ -16,35 +16,44 @@ export type AdditionalRouteConfig = {
|
|
|
16
16
|
hasChildren: boolean
|
|
17
17
|
expandedRouteNames: string[]
|
|
18
18
|
parts: string[]
|
|
19
|
+
staticPartCount: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface UrlWithReactNavigationConcessions {
|
|
23
|
+
path: string
|
|
24
|
+
nonstandardPathname: string
|
|
25
|
+
hash: string
|
|
26
|
+
pathWithoutGroups: string
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
export function getUrlWithReactNavigationConcessions(
|
|
22
30
|
path: string,
|
|
23
31
|
baseUrl: string | undefined = process.env.EXPO_BASE_URL
|
|
24
|
-
) {
|
|
25
|
-
|
|
32
|
+
): UrlWithReactNavigationConcessions {
|
|
33
|
+
const pathWithoutGroups = stripGroupSegmentsFromPath(stripBaseUrl(path, baseUrl))
|
|
34
|
+
|
|
35
|
+
let pathname = ''
|
|
36
|
+
let hash = ''
|
|
26
37
|
try {
|
|
27
|
-
|
|
38
|
+
// NOTE: This used to use a dummy base URL for parsing (phony.example)
|
|
39
|
+
// However, this seems to get flagged since it's preserved 1:1 in the output bytecode by certain scanners
|
|
40
|
+
// Instead, we use an empty `file:` URL. This will still perform `pathname` normalization, search parameter parsing
|
|
41
|
+
// encoding, and all other logic, except the logic that applies to hostnames and protocols, and also not leave a
|
|
42
|
+
// dummy URL in the output bytecode
|
|
43
|
+
const parsed = new URL(path, 'file:')
|
|
44
|
+
pathname = parsed.pathname
|
|
45
|
+
hash = parsed.hash
|
|
28
46
|
} catch {
|
|
29
47
|
// Do nothing with invalid URLs.
|
|
30
|
-
return {
|
|
31
|
-
path,
|
|
32
|
-
cleanUrl: '',
|
|
33
|
-
nonstandardPathname: '',
|
|
34
|
-
url: new URL('https://phony.example'),
|
|
35
|
-
}
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
const pathname = parsed.pathname
|
|
39
50
|
const withoutBaseUrl = stripBaseUrl(pathname, baseUrl)
|
|
40
|
-
const pathWithoutGroups = stripGroupSegmentsFromPath(stripBaseUrl(path, baseUrl))
|
|
41
|
-
|
|
42
|
-
// Make sure there is a trailing slash
|
|
43
51
|
return {
|
|
44
|
-
// The slashes are at the end, not the beginning
|
|
45
52
|
path,
|
|
53
|
+
// Make sure there is a trailing slash
|
|
54
|
+
// The slashes are at the end, not the beginning
|
|
46
55
|
nonstandardPathname: withoutBaseUrl.replace(/^\/+/g, '').replace(/\/+$/g, '') + '/',
|
|
47
|
-
|
|
56
|
+
hash,
|
|
48
57
|
pathWithoutGroups,
|
|
49
58
|
}
|
|
50
59
|
}
|
|
@@ -145,6 +154,13 @@ export function getRouteConfigSorter(previousSegments: string[] = []) {
|
|
|
145
154
|
return 1
|
|
146
155
|
}
|
|
147
156
|
|
|
157
|
+
/*
|
|
158
|
+
* If the routes have any static segments, the one with the most static segments should be higher
|
|
159
|
+
*/
|
|
160
|
+
if (a.staticPartCount !== b.staticPartCount) {
|
|
161
|
+
return b.staticPartCount - a.staticPartCount
|
|
162
|
+
}
|
|
163
|
+
|
|
148
164
|
/*
|
|
149
165
|
* If both are static/dynamic or a layout file, then we check group similarity
|
|
150
166
|
*/
|
|
@@ -312,15 +328,23 @@ export function createConfigItemAdditionalProperties(
|
|
|
312
328
|
): Omit<AdditionalRouteConfig, 'isInitial'> {
|
|
313
329
|
const parts: string[] = []
|
|
314
330
|
let isDynamic = false
|
|
331
|
+
let staticPartCount = 0
|
|
315
332
|
const isIndex = screen === 'index' || screen.endsWith('/index')
|
|
316
333
|
|
|
317
334
|
for (const part of pattern.split('/')) {
|
|
318
335
|
if (part) {
|
|
319
336
|
// If any part is dynamic, then the route is dynamic
|
|
320
|
-
|
|
337
|
+
const isDynamicPart =
|
|
338
|
+
part.startsWith(':') || part.startsWith('*') || part.includes('*not-found')
|
|
339
|
+
|
|
340
|
+
isDynamic ||= isDynamicPart
|
|
321
341
|
|
|
322
342
|
if (!matchGroupName(part)) {
|
|
323
343
|
parts.push(part)
|
|
344
|
+
|
|
345
|
+
if (!isDynamicPart) {
|
|
346
|
+
staticPartCount++
|
|
347
|
+
}
|
|
324
348
|
}
|
|
325
349
|
}
|
|
326
350
|
}
|
|
@@ -330,6 +354,7 @@ export function createConfigItemAdditionalProperties(
|
|
|
330
354
|
|
|
331
355
|
if (isIndex) {
|
|
332
356
|
parts.push('index')
|
|
357
|
+
staticPartCount++
|
|
333
358
|
}
|
|
334
359
|
|
|
335
360
|
return {
|
|
@@ -337,6 +362,7 @@ export function createConfigItemAdditionalProperties(
|
|
|
337
362
|
isIndex,
|
|
338
363
|
hasChildren,
|
|
339
364
|
parts,
|
|
365
|
+
staticPartCount,
|
|
340
366
|
userReadableName: [...routeNames.slice(0, -1), config.path || screen].join('/'),
|
|
341
367
|
expandedRouteNames: routeNames.flatMap((name) => {
|
|
342
368
|
return name.split('/')
|
|
@@ -350,7 +376,7 @@ export function parseQueryParamsExtended(
|
|
|
350
376
|
parseConfig?: Record<string, (value: string) => any>,
|
|
351
377
|
hash?: string
|
|
352
378
|
) {
|
|
353
|
-
const searchParams = new URL(path, '
|
|
379
|
+
const searchParams = new URL(path, 'file:').searchParams
|
|
354
380
|
const params: Record<string, string | string[]> = Object.create(null)
|
|
355
381
|
|
|
356
382
|
if (hash) {
|
|
@@ -189,7 +189,7 @@ export function useLinking(
|
|
|
189
189
|
// If the link were handled, it gets cleared in NavigationContainer
|
|
190
190
|
onUnhandledLinking(extractPathFromURL(prefixes, url))
|
|
191
191
|
const rootState = navigation.getRootState()
|
|
192
|
-
if (state.routes.some((r) => !rootState?.routeNames
|
|
192
|
+
if (state.routes.some((r) => !rootState?.routeNames?.includes(r.name))) {
|
|
193
193
|
return
|
|
194
194
|
}
|
|
195
195
|
|
package/src/fork/useLinking.ts
CHANGED
|
@@ -22,6 +22,7 @@ import isEqual from 'fast-deep-equal'
|
|
|
22
22
|
import * as React from 'react'
|
|
23
23
|
// @modified - start
|
|
24
24
|
// import { ServerContext } from '@react-navigation/web';
|
|
25
|
+
import { rootState as routerRootState } from '../router/router'
|
|
25
26
|
import { ServerLocationContext } from '../router/serverLocationContext'
|
|
26
27
|
import { createMemoryHistory } from './createMemoryHistory'
|
|
27
28
|
import { appendBaseUrl } from './getPathFromState-mods'
|
|
@@ -158,7 +159,7 @@ export function useLinking(
|
|
|
158
159
|
const rootState = navigation?.getRootState()
|
|
159
160
|
// Make sure that the routes in the state exist in the root navigator
|
|
160
161
|
// Otherwise there's an error in the linking configuration
|
|
161
|
-
return state?.routes.some((r) => !rootState?.routeNames
|
|
162
|
+
return state?.routes.some((r) => !rootState?.routeNames?.includes(r.name))
|
|
162
163
|
},
|
|
163
164
|
[ref]
|
|
164
165
|
)
|
|
@@ -180,8 +181,15 @@ export function useLinking(
|
|
|
180
181
|
|
|
181
182
|
const path = location ? location.pathname + location.search : undefined
|
|
182
183
|
|
|
184
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
185
|
+
console.info(`[one] 🔍 getInitialState path=${path}`)
|
|
186
|
+
}
|
|
187
|
+
|
|
183
188
|
if (path) {
|
|
184
189
|
value = getStateFromPathRef.current(path, configRef.current)
|
|
190
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
191
|
+
console.info(`[one] 🔍 getInitialState result:`, JSON.stringify(value, null, 2))
|
|
192
|
+
}
|
|
185
193
|
}
|
|
186
194
|
|
|
187
195
|
// If the link were handled, it gets cleared in NavigationContainer
|
|
@@ -223,6 +231,12 @@ export function useLinking(
|
|
|
223
231
|
|
|
224
232
|
const previousIndex = previousIndexRef.current ?? 0
|
|
225
233
|
|
|
234
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
235
|
+
console.info(
|
|
236
|
+
`[one] 📜 history.listen path=${path} index=${index} prevIndex=${previousIndex}`
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
226
240
|
previousIndexRef.current = index
|
|
227
241
|
pendingPopStatePathRef.current = path
|
|
228
242
|
|
|
@@ -232,12 +246,19 @@ export function useLinking(
|
|
|
232
246
|
const record = history.get(index)
|
|
233
247
|
|
|
234
248
|
if (record?.path === path && record?.state) {
|
|
249
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
250
|
+
console.info(`[one] 📜 history record found, resetRoot to:`, record.state)
|
|
251
|
+
}
|
|
235
252
|
navigation.resetRoot(record.state)
|
|
236
253
|
return
|
|
237
254
|
}
|
|
238
255
|
|
|
239
256
|
const state = getStateFromPathRef.current(path, configRef.current)
|
|
240
257
|
|
|
258
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
259
|
+
console.info(`[one] 📜 getStateFromPath result:`, state)
|
|
260
|
+
}
|
|
261
|
+
|
|
241
262
|
// We should only dispatch an action when going forward
|
|
242
263
|
// Otherwise the action will likely add items to history, which would mess things up
|
|
243
264
|
if (state) {
|
|
@@ -246,6 +267,9 @@ export function useLinking(
|
|
|
246
267
|
// Make sure that the routes in the state exist in the root navigator
|
|
247
268
|
// Otherwise there's an error in the linking configuration
|
|
248
269
|
if (validateRoutesNotExistInRootState(state)) {
|
|
270
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
271
|
+
console.info(`[one] 📜 routes not in root state, skipping`)
|
|
272
|
+
}
|
|
249
273
|
return
|
|
250
274
|
}
|
|
251
275
|
|
|
@@ -256,6 +280,10 @@ export function useLinking(
|
|
|
256
280
|
) {
|
|
257
281
|
const action = getActionFromStateRef.current(state, configRef.current)
|
|
258
282
|
|
|
283
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
284
|
+
console.info(`[one] 📜 dispatching action:`, action)
|
|
285
|
+
}
|
|
286
|
+
|
|
259
287
|
if (action !== undefined) {
|
|
260
288
|
try {
|
|
261
289
|
navigation.dispatch(action)
|
|
@@ -269,13 +297,22 @@ export function useLinking(
|
|
|
269
297
|
)
|
|
270
298
|
}
|
|
271
299
|
} else {
|
|
300
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
301
|
+
console.info(`[one] 📜 no action, resetRoot`)
|
|
302
|
+
}
|
|
272
303
|
navigation.resetRoot(state)
|
|
273
304
|
}
|
|
274
305
|
} else {
|
|
306
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
307
|
+
console.info(`[one] 📜 going back, resetRoot`)
|
|
308
|
+
}
|
|
275
309
|
navigation.resetRoot(state)
|
|
276
310
|
}
|
|
277
311
|
} else {
|
|
278
312
|
// if current path didn't return any state, we should revert to initial state
|
|
313
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
314
|
+
console.info(`[one] 📜 no state for path, resetRoot to undefined`)
|
|
315
|
+
}
|
|
279
316
|
navigation.resetRoot(state)
|
|
280
317
|
}
|
|
281
318
|
})
|
|
@@ -292,6 +329,11 @@ export function useLinking(
|
|
|
292
329
|
): string => {
|
|
293
330
|
let path
|
|
294
331
|
|
|
332
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
333
|
+
console.info(`[one] 📜 getPathForRoute - route:`, route)
|
|
334
|
+
console.info(`[one] 📜 getPathForRoute - state:`, JSON.stringify(state, null, 2))
|
|
335
|
+
}
|
|
336
|
+
|
|
295
337
|
// If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
|
|
296
338
|
// This makes sure that we preserve the original URL for wildcard routes
|
|
297
339
|
if (route?.path) {
|
|
@@ -315,6 +357,9 @@ export function useLinking(
|
|
|
315
357
|
|
|
316
358
|
if (path == null) {
|
|
317
359
|
path = getPathFromStateRef.current(state, configRef.current)
|
|
360
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
361
|
+
console.info(`[one] 📜 getPathForRoute - computed from state:`, path)
|
|
362
|
+
}
|
|
318
363
|
}
|
|
319
364
|
|
|
320
365
|
// @modified - start: One will handle hashes itself, so these lines are not needed
|
|
@@ -340,14 +385,41 @@ export function useLinking(
|
|
|
340
385
|
if (ref.current) {
|
|
341
386
|
// We need to record the current metadata on the first render if they aren't set
|
|
342
387
|
// This will allow the initial state to be in the history entry
|
|
343
|
-
|
|
388
|
+
// @modified - start: Use routerRootState instead of getRootState() to avoid stale state
|
|
389
|
+
// getRootState() can return incomplete state during initial render before children mount
|
|
390
|
+
// routerRootState is updated via navigation listener callbacks which only fire with complete state
|
|
391
|
+
const refState = ref.current.getRootState()
|
|
392
|
+
const state = (routerRootState || refState) as NavigationState | undefined
|
|
393
|
+
|
|
394
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
395
|
+
console.info(
|
|
396
|
+
`[one] 📜 useEffect initial state check - refState:`,
|
|
397
|
+
JSON.stringify(refState, null, 2)
|
|
398
|
+
)
|
|
399
|
+
console.info(
|
|
400
|
+
`[one] 📜 useEffect initial state check - routerRootState:`,
|
|
401
|
+
JSON.stringify(routerRootState, null, 2)
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
// @modified - end
|
|
344
405
|
|
|
345
406
|
if (state) {
|
|
346
407
|
const route = findFocusedRoute(state)
|
|
408
|
+
|
|
409
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
410
|
+
console.info(`[one] 📜 useEffect focused route:`, route)
|
|
411
|
+
}
|
|
412
|
+
|
|
347
413
|
const path = getPathForRoute(route, state)
|
|
348
414
|
|
|
415
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
416
|
+
console.info(`[one] 📜 initial history.replace - state:`, JSON.stringify(state, null, 2))
|
|
417
|
+
console.info(`[one] 📜 initial history.replace - focusedRoute:`, route)
|
|
418
|
+
console.info(`[one] 📜 initial history.replace - computed path:`, path)
|
|
419
|
+
}
|
|
420
|
+
|
|
349
421
|
if (previousStateRef.current === undefined) {
|
|
350
|
-
previousStateRef.current =
|
|
422
|
+
previousStateRef.current = refState
|
|
351
423
|
}
|
|
352
424
|
|
|
353
425
|
history.replace({ path, state })
|
|
@@ -362,7 +434,10 @@ export function useLinking(
|
|
|
362
434
|
}
|
|
363
435
|
|
|
364
436
|
const previousState = previousStateRef.current
|
|
365
|
-
|
|
437
|
+
// @modified - start: Use routerRootState for path calculation, refState for comparison
|
|
438
|
+
const refState = navigation.getRootState()
|
|
439
|
+
const state = (routerRootState || refState) as NavigationState | undefined
|
|
440
|
+
// @modified - end
|
|
366
441
|
|
|
367
442
|
// root state may not available, for example when root navigators switch inside the container
|
|
368
443
|
if (!state) {
|
|
@@ -373,7 +448,7 @@ export function useLinking(
|
|
|
373
448
|
const route = findFocusedRoute(state)
|
|
374
449
|
const path = getPathForRoute(route, state)
|
|
375
450
|
|
|
376
|
-
previousStateRef.current =
|
|
451
|
+
previousStateRef.current = refState
|
|
377
452
|
pendingPopStatePathRef.current = undefined
|
|
378
453
|
|
|
379
454
|
// To detect the kind of state change, we need to:
|