one 1.24.5 → 1.24.6
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/fork/useLinking.cjs +3 -2
- package/dist/cjs/router/conditionalSlotPathname.test.cjs +137 -0
- package/dist/cjs/router/conditionalSlotPathname.test.native.js +193 -0
- package/dist/cjs/router/conditionalSlotPathname.test.native.js.map +1 -0
- package/dist/cjs/router/isStateAwaitingNavigatorMount.cjs +48 -0
- package/dist/cjs/router/isStateAwaitingNavigatorMount.native.js +71 -0
- package/dist/cjs/router/isStateAwaitingNavigatorMount.native.js.map +1 -0
- package/dist/cjs/router/router.cjs +5 -0
- package/dist/cjs/router/router.native.js +5 -0
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/views/RootErrorBoundary.cjs +14 -12
- package/dist/cjs/views/RootErrorBoundary.native.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +4 -3
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/router/conditionalSlotPathname.test.mjs +114 -0
- package/dist/esm/router/conditionalSlotPathname.test.mjs.map +1 -0
- package/dist/esm/router/conditionalSlotPathname.test.native.js +167 -0
- package/dist/esm/router/conditionalSlotPathname.test.native.js.map +1 -0
- package/dist/esm/router/isStateAwaitingNavigatorMount.mjs +23 -0
- package/dist/esm/router/isStateAwaitingNavigatorMount.mjs.map +1 -0
- package/dist/esm/router/isStateAwaitingNavigatorMount.native.js +43 -0
- package/dist/esm/router/isStateAwaitingNavigatorMount.native.js.map +1 -0
- package/dist/esm/router/router.mjs +5 -0
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +5 -0
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/views/RootErrorBoundary.mjs +14 -12
- package/dist/esm/views/RootErrorBoundary.mjs.map +1 -1
- package/dist/esm/views/RootErrorBoundary.native.js.map +1 -1
- package/package.json +9 -9
- package/src/fork/useLinking.ts +13 -12
- package/src/router/conditionalSlotPathname.test.tsx +147 -0
- package/src/router/isStateAwaitingNavigatorMount.ts +64 -0
- package/src/router/router.ts +13 -0
- package/src/views/RootErrorBoundary.web.tsx +18 -13
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/router/conditionalSlotPathname.test.d.ts +2 -0
- package/types/router/conditionalSlotPathname.test.d.ts.map +1 -0
- package/types/router/isStateAwaitingNavigatorMount.d.ts +28 -0
- package/types/router/isStateAwaitingNavigatorMount.d.ts.map +1 -0
- package/types/router/router.d.ts.map +1 -1
- package/types/views/RootErrorBoundary.web.d.ts.map +1 -1
|
@@ -44,6 +44,7 @@ var React = __toESM(require("react"), 1);
|
|
|
44
44
|
var import_matchers = require("../router/matchers.cjs");
|
|
45
45
|
var import_interceptRoutes = require("../router/interceptRoutes.cjs");
|
|
46
46
|
var import_router = require("../router/router.cjs");
|
|
47
|
+
var import_isStateAwaitingNavigatorMount = require("../router/isStateAwaitingNavigatorMount.cjs");
|
|
47
48
|
var import_serverLocationContext = require("../router/serverLocationContext.cjs");
|
|
48
49
|
var import_Navigator = require("../views/Navigator.cjs");
|
|
49
50
|
var import_createMemoryHistory = require("./createMemoryHistory.cjs");
|
|
@@ -401,9 +402,9 @@ function useLinking(ref, {
|
|
|
401
402
|
}
|
|
402
403
|
const pendingPath = pendingPopStatePathRef.current;
|
|
403
404
|
const route = (0, import_core.findFocusedRoute)(state);
|
|
404
|
-
if (
|
|
405
|
+
if ((0, import_isStateAwaitingNavigatorMount.isStateAwaitingNavigatorMount)(state, import_router.routeNode)) {
|
|
405
406
|
if (process.env.ONE_DEBUG_ROUTER) {
|
|
406
|
-
console.info(`[one] \u{1F4DC} onStateChange - skipping:
|
|
407
|
+
console.info(`[one] \u{1F4DC} onStateChange - skipping: navigator below`, route?.name, `has not mounted`);
|
|
407
408
|
}
|
|
408
409
|
return;
|
|
409
410
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
var import_react = __toESM(require("react"), 1);
|
|
26
|
+
var import_react_test_renderer = __toESM(require("react-test-renderer"), 1);
|
|
27
|
+
var import_vitest = require("vitest");
|
|
28
|
+
var import_hooks = require("../hooks.cjs");
|
|
29
|
+
var import_Root = require("../Root.cjs");
|
|
30
|
+
var import_Navigator = require("../views/Navigator.cjs");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
33
|
+
globalThis.requestAnimationFrame ??= cb => setTimeout(() => cb(0), 0);
|
|
34
|
+
globalThis.cancelAnimationFrame ??= id => clearTimeout(id);
|
|
35
|
+
const routerRoot = "app";
|
|
36
|
+
function makeRoutes(modules) {
|
|
37
|
+
globalThis["__vxrnVersion"] = (globalThis["__vxrnVersion"] ?? 0) + 1;
|
|
38
|
+
const routes = {};
|
|
39
|
+
for (const [file, module2] of Object.entries(modules)) {
|
|
40
|
+
routes[`/${routerRoot}/${file}`] = module2;
|
|
41
|
+
}
|
|
42
|
+
return routes;
|
|
43
|
+
}
|
|
44
|
+
const slotLayout = {
|
|
45
|
+
default: () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Navigator.Slot, {})
|
|
46
|
+
};
|
|
47
|
+
const leaf = label => ({
|
|
48
|
+
default: () => label
|
|
49
|
+
});
|
|
50
|
+
function routeTreeWithGate(gate) {
|
|
51
|
+
const Gate = gate;
|
|
52
|
+
return makeRoutes({
|
|
53
|
+
"_layout.tsx": slotLayout,
|
|
54
|
+
"(app)/_layout.tsx": {
|
|
55
|
+
default: () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(Gate, {
|
|
56
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Navigator.Slot, {})
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
"(app)/index.tsx": leaf("app-index"),
|
|
60
|
+
"(app)/project/_layout.tsx": slotLayout,
|
|
61
|
+
"(app)/project/[projectId]/_layout.tsx": slotLayout,
|
|
62
|
+
"(app)/project/[projectId]/[sessionId]/_layout.tsx": slotLayout,
|
|
63
|
+
"(app)/project/[projectId]/[sessionId]/index.tsx": leaf("session"),
|
|
64
|
+
"(site)/_layout.tsx": slotLayout,
|
|
65
|
+
"(site)/pricing.tsx": leaf("pricing")
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function renderAt(path, routes) {
|
|
69
|
+
let renderer;
|
|
70
|
+
(0, import_react_test_renderer.act)(() => {
|
|
71
|
+
renderer = import_react_test_renderer.default.create(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Root.Root, {
|
|
72
|
+
path,
|
|
73
|
+
routes,
|
|
74
|
+
routerRoot,
|
|
75
|
+
isClient: false
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
return renderer;
|
|
79
|
+
}
|
|
80
|
+
function bodyText(renderer) {
|
|
81
|
+
const collect = node => typeof node === "string" ? node : Array.isArray(node) ? node.map(collect).join("") : node ? collect(node.children ?? []) : "";
|
|
82
|
+
return collect(renderer.toJSON());
|
|
83
|
+
}
|
|
84
|
+
(0, import_vitest.describe)("a layout that renders something other than its <Slot />", () => {
|
|
85
|
+
(0, import_vitest.it)("does not move the pathname while the URL stands still", () => {
|
|
86
|
+
const pathnames = [];
|
|
87
|
+
let setBlocked;
|
|
88
|
+
function Probe() {
|
|
89
|
+
const pathname = (0, import_hooks.usePathname)();
|
|
90
|
+
if (pathnames[pathnames.length - 1] !== pathname) pathnames.push(pathname);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function Gate({
|
|
94
|
+
children
|
|
95
|
+
}) {
|
|
96
|
+
const [blocked, set] = import_react.default.useState(true);
|
|
97
|
+
setBlocked = set;
|
|
98
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
99
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(Probe, {}), blocked ? "placeholder" : children]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const renderer = renderAt("/project/p1/main", routeTreeWithGate(Gate));
|
|
103
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("placeholder");
|
|
104
|
+
(0, import_react_test_renderer.act)(() => setBlocked(false));
|
|
105
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("session");
|
|
106
|
+
(0, import_react_test_renderer.act)(() => setBlocked(true));
|
|
107
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("placeholder");
|
|
108
|
+
(0, import_react_test_renderer.act)(() => setBlocked(false));
|
|
109
|
+
(0, import_vitest.expect)(pathnames).toEqual(["/project/p1/main"]);
|
|
110
|
+
});
|
|
111
|
+
(0, import_vitest.it)("settles when the gate itself reads the pathname", async () => {
|
|
112
|
+
let renders = 0;
|
|
113
|
+
let requestBlock;
|
|
114
|
+
function Gate({
|
|
115
|
+
children
|
|
116
|
+
}) {
|
|
117
|
+
const pathname = (0, import_hooks.usePathname)();
|
|
118
|
+
const [blockRequested, setBlockRequested] = import_react.default.useState(false);
|
|
119
|
+
requestBlock = () => setBlockRequested(true);
|
|
120
|
+
renders++;
|
|
121
|
+
if (renders > 100) {
|
|
122
|
+
throw new Error(`gate rendered ${renders} times without settling`);
|
|
123
|
+
}
|
|
124
|
+
const blocked = blockRequested && pathname.startsWith("/project/");
|
|
125
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
126
|
+
children: blocked ? "blocked" : children
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const renderer = renderAt("/project/p1/main", routeTreeWithGate(Gate));
|
|
130
|
+
await (0, import_react_test_renderer.act)(async () => {});
|
|
131
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("session");
|
|
132
|
+
await (0, import_react_test_renderer.act)(async () => requestBlock());
|
|
133
|
+
await (0, import_react_test_renderer.act)(async () => {});
|
|
134
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("blocked");
|
|
135
|
+
(0, import_vitest.expect)(renders).toBeLessThan(20);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: () => from[key],
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
+
var import_react = __toESM(require("react"), 1);
|
|
29
|
+
var import_react_test_renderer = __toESM(require("react-test-renderer"), 1);
|
|
30
|
+
var import_vitest = require("vitest");
|
|
31
|
+
var import_hooks = require("../hooks.native.js");
|
|
32
|
+
var import_Root = require("../Root.native.js");
|
|
33
|
+
var import_Navigator = require("../views/Navigator.native.js");
|
|
34
|
+
var _globalThis;
|
|
35
|
+
var _requestAnimationFrame;
|
|
36
|
+
var _globalThis1;
|
|
37
|
+
var _cancelAnimationFrame;
|
|
38
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
39
|
+
(_requestAnimationFrame = (_globalThis = globalThis).requestAnimationFrame) !== null && _requestAnimationFrame !== void 0 ? _requestAnimationFrame : _globalThis.requestAnimationFrame = function (cb) {
|
|
40
|
+
return setTimeout(function () {
|
|
41
|
+
return cb(0);
|
|
42
|
+
}, 0);
|
|
43
|
+
};
|
|
44
|
+
(_cancelAnimationFrame = (_globalThis1 = globalThis).cancelAnimationFrame) !== null && _cancelAnimationFrame !== void 0 ? _cancelAnimationFrame : _globalThis1.cancelAnimationFrame = function (id) {
|
|
45
|
+
return clearTimeout(id);
|
|
46
|
+
};
|
|
47
|
+
var routerRoot = "app";
|
|
48
|
+
function makeRoutes(modules) {
|
|
49
|
+
var _globalThis___vxrnVersion;
|
|
50
|
+
globalThis["__vxrnVersion"] = ((_globalThis___vxrnVersion = globalThis["__vxrnVersion"]) !== null && _globalThis___vxrnVersion !== void 0 ? _globalThis___vxrnVersion : 0) + 1;
|
|
51
|
+
var routes = {};
|
|
52
|
+
var _iteratorNormalCompletion = true,
|
|
53
|
+
_didIteratorError = false,
|
|
54
|
+
_iteratorError = void 0;
|
|
55
|
+
try {
|
|
56
|
+
for (var _iterator = Object.entries(modules)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
57
|
+
var [file, module2] = _step.value;
|
|
58
|
+
routes[`/${routerRoot}/${file}`] = module2;
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_didIteratorError = true;
|
|
62
|
+
_iteratorError = err;
|
|
63
|
+
} finally {
|
|
64
|
+
try {
|
|
65
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
66
|
+
_iterator.return();
|
|
67
|
+
}
|
|
68
|
+
} finally {
|
|
69
|
+
if (_didIteratorError) {
|
|
70
|
+
throw _iteratorError;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return routes;
|
|
75
|
+
}
|
|
76
|
+
var slotLayout = {
|
|
77
|
+
default: function () {
|
|
78
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Navigator.Slot, {});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var leaf = function (label) {
|
|
82
|
+
return {
|
|
83
|
+
default: function () {
|
|
84
|
+
return label;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
function routeTreeWithGate(gate) {
|
|
89
|
+
var Gate = gate;
|
|
90
|
+
return makeRoutes({
|
|
91
|
+
"_layout.tsx": slotLayout,
|
|
92
|
+
"(app)/_layout.tsx": {
|
|
93
|
+
default: function () {
|
|
94
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Gate, {
|
|
95
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Navigator.Slot, {})
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"(app)/index.tsx": leaf("app-index"),
|
|
100
|
+
"(app)/project/_layout.tsx": slotLayout,
|
|
101
|
+
"(app)/project/[projectId]/_layout.tsx": slotLayout,
|
|
102
|
+
"(app)/project/[projectId]/[sessionId]/_layout.tsx": slotLayout,
|
|
103
|
+
"(app)/project/[projectId]/[sessionId]/index.tsx": leaf("session"),
|
|
104
|
+
"(site)/_layout.tsx": slotLayout,
|
|
105
|
+
"(site)/pricing.tsx": leaf("pricing")
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function renderAt(path, routes) {
|
|
109
|
+
var renderer;
|
|
110
|
+
(0, import_react_test_renderer.act)(function () {
|
|
111
|
+
renderer = import_react_test_renderer.default.create(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Root.Root, {
|
|
112
|
+
path,
|
|
113
|
+
routes,
|
|
114
|
+
routerRoot,
|
|
115
|
+
isClient: false
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
118
|
+
return renderer;
|
|
119
|
+
}
|
|
120
|
+
function bodyText(renderer) {
|
|
121
|
+
var collect = function (node) {
|
|
122
|
+
var _node_children;
|
|
123
|
+
return typeof node === "string" ? node : Array.isArray(node) ? node.map(collect).join("") : node ? collect((_node_children = node.children) !== null && _node_children !== void 0 ? _node_children : []) : "";
|
|
124
|
+
};
|
|
125
|
+
return collect(renderer.toJSON());
|
|
126
|
+
}
|
|
127
|
+
(0, import_vitest.describe)("a layout that renders something other than its <Slot />", function () {
|
|
128
|
+
(0, import_vitest.it)("does not move the pathname while the URL stands still", function () {
|
|
129
|
+
var pathnames = [];
|
|
130
|
+
var setBlocked;
|
|
131
|
+
function Probe() {
|
|
132
|
+
var pathname = (0, import_hooks.usePathname)();
|
|
133
|
+
if (pathnames[pathnames.length - 1] !== pathname) pathnames.push(pathname);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function Gate(param) {
|
|
137
|
+
var {
|
|
138
|
+
children
|
|
139
|
+
} = param;
|
|
140
|
+
var [blocked, set] = import_react.default.useState(true);
|
|
141
|
+
setBlocked = set;
|
|
142
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
143
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(Probe, {}), blocked ? "placeholder" : children]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
var renderer = renderAt("/project/p1/main", routeTreeWithGate(Gate));
|
|
147
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("placeholder");
|
|
148
|
+
(0, import_react_test_renderer.act)(function () {
|
|
149
|
+
return setBlocked(false);
|
|
150
|
+
});
|
|
151
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("session");
|
|
152
|
+
(0, import_react_test_renderer.act)(function () {
|
|
153
|
+
return setBlocked(true);
|
|
154
|
+
});
|
|
155
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("placeholder");
|
|
156
|
+
(0, import_react_test_renderer.act)(function () {
|
|
157
|
+
return setBlocked(false);
|
|
158
|
+
});
|
|
159
|
+
(0, import_vitest.expect)(pathnames).toEqual(["/project/p1/main"]);
|
|
160
|
+
});
|
|
161
|
+
(0, import_vitest.it)("settles when the gate itself reads the pathname", async function () {
|
|
162
|
+
var renders = 0;
|
|
163
|
+
var requestBlock;
|
|
164
|
+
function Gate(param) {
|
|
165
|
+
var {
|
|
166
|
+
children
|
|
167
|
+
} = param;
|
|
168
|
+
var pathname = (0, import_hooks.usePathname)();
|
|
169
|
+
var [blockRequested, setBlockRequested] = import_react.default.useState(false);
|
|
170
|
+
requestBlock = function () {
|
|
171
|
+
return setBlockRequested(true);
|
|
172
|
+
};
|
|
173
|
+
renders++;
|
|
174
|
+
if (renders > 100) {
|
|
175
|
+
throw new Error(`gate rendered ${renders} times without settling`);
|
|
176
|
+
}
|
|
177
|
+
var blocked = blockRequested && pathname.startsWith("/project/");
|
|
178
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
179
|
+
children: blocked ? "blocked" : children
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
var renderer = renderAt("/project/p1/main", routeTreeWithGate(Gate));
|
|
183
|
+
await (0, import_react_test_renderer.act)(async function () {});
|
|
184
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("session");
|
|
185
|
+
await (0, import_react_test_renderer.act)(async function () {
|
|
186
|
+
return requestBlock();
|
|
187
|
+
});
|
|
188
|
+
await (0, import_react_test_renderer.act)(async function () {});
|
|
189
|
+
(0, import_vitest.expect)(bodyText(renderer)).toBe("blocked");
|
|
190
|
+
(0, import_vitest.expect)(renders).toBeLessThan(20);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
//# sourceMappingURL=conditionalSlotPathname.test.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["import_jsx_runtime","require","import_react","__toESM","import_react_test_renderer","import_vitest","import_hooks","import_Root","import_Navigator","_globalThis","_requestAnimationFrame","_globalThis1","_cancelAnimationFrame","globalThis","IS_REACT_ACT_ENVIRONMENT","requestAnimationFrame","cb","setTimeout","cancelAnimationFrame","id","clearTimeout","routerRoot","makeRoutes","modules","_globalThis___vxrnVersion","routes","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Object","entries","Symbol","iterator","_step","next","done","file","module2","value","err","return","slotLayout","default","jsx","Slot","leaf","label","routeTreeWithGate","gate","Gate","children","renderAt","path","renderer","act","create","Root","isClient","bodyText","collect","node","_node_children","Array","isArray","map","join","toJSON","describe","it"],"sources":["../../../src/router/conditionalSlotPathname.test.tsx"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var isStateAwaitingNavigatorMount_exports = {};
|
|
24
|
+
__export(isStateAwaitingNavigatorMount_exports, {
|
|
25
|
+
isStateAwaitingNavigatorMount: () => isStateAwaitingNavigatorMount
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(isStateAwaitingNavigatorMount_exports);
|
|
28
|
+
function focusedRouteOf(state) {
|
|
29
|
+
return typeof state.index === "number" ? state.routes[state.index] : state.routes[state.routes.length - 1];
|
|
30
|
+
}
|
|
31
|
+
function isStateAwaitingNavigatorMount(state, rootNode) {
|
|
32
|
+
if (!rootNode) return false;
|
|
33
|
+
let node = rootNode;
|
|
34
|
+
let current = state;
|
|
35
|
+
while (current?.routes?.length) {
|
|
36
|
+
const route = focusedRouteOf(current);
|
|
37
|
+
if (!route) return false;
|
|
38
|
+
const child = node.children.find(candidate => candidate.route === route.name);
|
|
39
|
+
if (!child) return false;
|
|
40
|
+
if (route.state) {
|
|
41
|
+
node = child;
|
|
42
|
+
current = route.state;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
return child.children.some(grandchild => !grandchild.internal);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var isStateAwaitingNavigatorMount_exports = {};
|
|
26
|
+
__export(isStateAwaitingNavigatorMount_exports, {
|
|
27
|
+
isStateAwaitingNavigatorMount: () => isStateAwaitingNavigatorMount
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(isStateAwaitingNavigatorMount_exports);
|
|
30
|
+
function _type_of(obj) {
|
|
31
|
+
"@swc/helpers - typeof";
|
|
32
|
+
|
|
33
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
34
|
+
}
|
|
35
|
+
function focusedRouteOf(state) {
|
|
36
|
+
return typeof state.index === "number" ? state.routes[state.index] : state.routes[state.routes.length - 1];
|
|
37
|
+
}
|
|
38
|
+
function isStateAwaitingNavigatorMount(state, rootNode) {
|
|
39
|
+
var _loop = function () {
|
|
40
|
+
var route = focusedRouteOf(current);
|
|
41
|
+
if (!route) return {
|
|
42
|
+
v: false
|
|
43
|
+
};
|
|
44
|
+
var child = node.children.find(function (candidate) {
|
|
45
|
+
return candidate.route === route.name;
|
|
46
|
+
});
|
|
47
|
+
if (!child) return {
|
|
48
|
+
v: false
|
|
49
|
+
};
|
|
50
|
+
if (route.state) {
|
|
51
|
+
node = child;
|
|
52
|
+
current = route.state;
|
|
53
|
+
return "continue";
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
v: child.children.some(function (grandchild) {
|
|
57
|
+
return !grandchild.internal;
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
var _current_routes;
|
|
62
|
+
if (!rootNode) return false;
|
|
63
|
+
var node = rootNode;
|
|
64
|
+
var current = state;
|
|
65
|
+
while (current === null || current === void 0 ? void 0 : (_current_routes = current.routes) === null || _current_routes === void 0 ? void 0 : _current_routes.length) {
|
|
66
|
+
var _ret = _loop();
|
|
67
|
+
if (_type_of(_ret) === "object") return _ret.v;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=isStateAwaitingNavigatorMount.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","isStateAwaitingNavigatorMount_exports","__export","isStateAwaitingNavigatorMount","module","exports","_type_of","obj","Symbol","constructor","focusedRouteOf","state","index","routes","length","rootNode","_loop","route","current","v","child","node","children","find","candidate","name"],"sources":["../../../src/router/isStateAwaitingNavigatorMount.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,qCAAA;AAAAC,QAAA,CAAAD,qCAAA;EAAAE,6BAAA,EAAAA,CAAA,KAAAA;AAAA;AAUAC,MAAA,CAAAC,OAAS,GAAAT,YAAe,CAAAK,qCAAqB;AAC3C,SAAOK,QAAOA,CAAAC,GAAA,EAAM;EAGtB;;EAkBO,OAASA,GAAA,WAAAC,MAAA,gBACd,IACAD,GAAA,CAAAE,WACS,KAAAD,MAAA,qBAAAD,GAAA;AACT;AAEA,SAAIG,cAAOA,CAAAC,KAAA;EACX,OAAI,OAAUA,KAAA,CAAAC,KAAA,gBAAAD,KAAA,CAAAE,MAAA,CAAAF,KAAA,CAAAC,KAAA,IAAAD,KAAA,CAAAE,MAAA,CAAAF,KAAA,CAAAE,MAAA,CAAAC,MAAA;AAEd;AACE,SAAAX,6BAA6BA,CAAAQ,KAAO,EAAAI,QAAA;EACpC,IAAAC,KAAK,YAAAA,CAAA,EAAc;IAKnB,IAAAC,KAAM,GAAAP,cAAa,CAAAQ,OAAe;IAClC,IAAI,CAACD,KAAA,EAAO,OAAO;MAEnBE,CAAA,EAAI;IACF;IACA,IAAAC,KAAA,GAAUC,IAAA,CAAAC,QAAM,CAAAC,IAAA,WAAAC,SAAA;MAChB,OAAAA,SAAA,CAAAP,KAAA,KAAAA,KAAA,CAAAQ,IAAA;IACF;IAIA,KAAAL,KAAO,SAAM;MACfD,CAAA;IAEA;IACF,IAAAF,KAAA,CAAAN,KAAA","ignoreList":[]}
|
|
@@ -89,6 +89,7 @@ var import_url = require("../utils/url.cjs");
|
|
|
89
89
|
var import_validateParams = require("../validateParams.cjs");
|
|
90
90
|
var import_findRouteNode = require("./findRouteNode.cjs");
|
|
91
91
|
var import_getRouteInfo = require("./getRouteInfo.cjs");
|
|
92
|
+
var import_isStateAwaitingNavigatorMount = require("./isStateAwaitingNavigatorMount.cjs");
|
|
92
93
|
var import_getRouteArtifactPath = require("./getRouteArtifactPath.cjs");
|
|
93
94
|
var import_getRoutes = require("./getRoutes.cjs");
|
|
94
95
|
var import_lastAction = require("./lastAction.cjs");
|
|
@@ -346,6 +347,10 @@ function getSortedRoutes() {
|
|
|
346
347
|
function updateState(state, nextStateParam = state) {
|
|
347
348
|
rootState = state;
|
|
348
349
|
nextState = nextStateParam;
|
|
350
|
+
if ((0, import_isStateAwaitingNavigatorMount.isStateAwaitingNavigatorMount)(state, routeNode)) {
|
|
351
|
+
if (process.env.ONE_DEBUG_ROUTER) console.info(`[one] \u{1F9ED} keeping ${routeInfo?.pathname}: a navigator has not mounted`);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
349
354
|
const nextRouteInfo = (0, import_getRouteInfo.getRouteInfo)(state);
|
|
350
355
|
if (pendingNavigationPathname === nextRouteInfo.pathname) pendingNavigationPathname = void 0;
|
|
351
356
|
if (!deepEqual(routeInfo, nextRouteInfo)) {
|
|
@@ -91,6 +91,7 @@ var import_url = require("../utils/url.native.js");
|
|
|
91
91
|
var import_validateParams = require("../validateParams.native.js");
|
|
92
92
|
var import_findRouteNode = require("./findRouteNode.native.js");
|
|
93
93
|
var import_getRouteInfo = require("./getRouteInfo.native.js");
|
|
94
|
+
var import_isStateAwaitingNavigatorMount = require("./isStateAwaitingNavigatorMount.native.js");
|
|
94
95
|
require("./getRouteArtifactPath.native.js");
|
|
95
96
|
var import_getRoutes = require("./getRoutes.native.js");
|
|
96
97
|
var import_lastAction = require("./lastAction.native.js");
|
|
@@ -451,6 +452,10 @@ function updateState(state) {
|
|
|
451
452
|
var nextStateParam = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : state;
|
|
452
453
|
rootState = state;
|
|
453
454
|
nextState = nextStateParam;
|
|
455
|
+
if ((0, import_isStateAwaitingNavigatorMount.isStateAwaitingNavigatorMount)(state, routeNode)) {
|
|
456
|
+
if (process.env.ONE_DEBUG_ROUTER) console.info(`[one] \u{1F9ED} keeping ${routeInfo === null || routeInfo === void 0 ? void 0 : routeInfo.pathname}: a navigator has not mounted`);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
454
459
|
var nextRouteInfo = (0, import_getRouteInfo.getRouteInfo)(state);
|
|
455
460
|
if (pendingNavigationPathname === nextRouteInfo.pathname) pendingNavigationPathname = void 0;
|
|
456
461
|
if (!deepEqual(routeInfo, nextRouteInfo)) {
|