@uniflowed/router 0.0.0-alpha.8 → 0.0.0-alpha.9
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/internal/runtime.js +23 -7
- package/package.json +2 -2
package/internal/runtime.js
CHANGED
|
@@ -1183,7 +1183,23 @@ export type AppProps = {|
|
|
|
1183
1183
|
readonly initial: ResolvedRoute,
|
|
1184
1184
|
|};
|
|
1185
1185
|
|
|
1186
|
-
|
|
1186
|
+
/**
|
|
1187
|
+
* Whether there is a document to navigate.
|
|
1188
|
+
*
|
|
1189
|
+
* Asked every time rather than answered once at module scope, and the
|
|
1190
|
+
* difference is not a style preference. The answer is a constant inside a
|
|
1191
|
+
* browser bundle and inside a server process; it is *not* a constant inside a
|
|
1192
|
+
* test runner, where a DOM is installed on the first render and one worker
|
|
1193
|
+
* serves many files out of one module registry. Latched, the first file in a
|
|
1194
|
+
* worker to import this module decided for every file after it whether a
|
|
1195
|
+
* `Link` navigates or silently does nothing — and a server-rendering test
|
|
1196
|
+
* imports it before any document exists. See ubugeeei-prod/uf#445.
|
|
1197
|
+
*
|
|
1198
|
+
* The cost is a `typeof` per navigation, which is a navigation.
|
|
1199
|
+
*/
|
|
1200
|
+
function isBrowser(): boolean {
|
|
1201
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
1202
|
+
}
|
|
1187
1203
|
|
|
1188
1204
|
/**
|
|
1189
1205
|
* Provides the current route to the tree and performs navigation.
|
|
@@ -1198,7 +1214,7 @@ export component RouterProvider(url: string, initial: ResolvedRoute, children: R
|
|
|
1198
1214
|
const [pending, setPending] = useState<boolean>(false);
|
|
1199
1215
|
|
|
1200
1216
|
const navigate = useCallback(async (to: string, options?: NavigateOptions): Promise<void> => {
|
|
1201
|
-
if (!isBrowser) {
|
|
1217
|
+
if (!isBrowser()) {
|
|
1202
1218
|
return;
|
|
1203
1219
|
}
|
|
1204
1220
|
const target = new URL(to, window.location.href);
|
|
@@ -1244,7 +1260,7 @@ export component RouterProvider(url: string, initial: ResolvedRoute, children: R
|
|
|
1244
1260
|
}, []);
|
|
1245
1261
|
|
|
1246
1262
|
useEffect(() => {
|
|
1247
|
-
if (!isBrowser) {
|
|
1263
|
+
if (!isBrowser()) {
|
|
1248
1264
|
return undefined;
|
|
1249
1265
|
}
|
|
1250
1266
|
const onPopState = () => {
|
|
@@ -1274,7 +1290,7 @@ export component RouterProvider(url: string, initial: ResolvedRoute, children: R
|
|
|
1274
1290
|
push: (to, options) => navigate(to, options),
|
|
1275
1291
|
replace: (to) => navigate(to, { replace: true }),
|
|
1276
1292
|
prefetch: async (to) => {
|
|
1277
|
-
if (!isBrowser) {
|
|
1293
|
+
if (!isBrowser()) {
|
|
1278
1294
|
return;
|
|
1279
1295
|
}
|
|
1280
1296
|
const target = new URL(to, window.location.href);
|
|
@@ -1289,7 +1305,7 @@ export component RouterProvider(url: string, initial: ResolvedRoute, children: R
|
|
|
1289
1305
|
]);
|
|
1290
1306
|
},
|
|
1291
1307
|
refresh: async () => {
|
|
1292
|
-
if (!isBrowser) {
|
|
1308
|
+
if (!isBrowser()) {
|
|
1293
1309
|
return;
|
|
1294
1310
|
}
|
|
1295
1311
|
const nextResolved = await resolveMatch(
|
|
@@ -1301,12 +1317,12 @@ export component RouterProvider(url: string, initial: ResolvedRoute, children: R
|
|
|
1301
1317
|
});
|
|
1302
1318
|
},
|
|
1303
1319
|
back: () => {
|
|
1304
|
-
if (isBrowser) {
|
|
1320
|
+
if (isBrowser()) {
|
|
1305
1321
|
window.history.back();
|
|
1306
1322
|
}
|
|
1307
1323
|
},
|
|
1308
1324
|
forward: () => {
|
|
1309
|
-
if (isBrowser) {
|
|
1325
|
+
if (isBrowser()) {
|
|
1310
1326
|
window.history.forward();
|
|
1311
1327
|
}
|
|
1312
1328
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniflowed/router",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.9",
|
|
4
4
|
"description": "The file-system router for Flow React applications: matching, layouts, loaders, navigation, server rendering and hydration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"react-dom": ">=19"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@uniflowed/server": "0.0.0-alpha.
|
|
34
|
+
"@uniflowed/server": "0.0.0-alpha.9"
|
|
35
35
|
}
|
|
36
36
|
}
|