@rebask/core 0.1.3 → 0.1.5
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.
|
@@ -3,6 +3,9 @@ type PrefetchStrategy = PrefetchToken | {
|
|
|
3
3
|
desktop?: PrefetchToken;
|
|
4
4
|
mobile?: PrefetchToken;
|
|
5
5
|
};
|
|
6
|
+
/** Remember a URL whose route tree request returned something other than a page. */
|
|
7
|
+
export declare function markDocumentUrl(url: string): void;
|
|
8
|
+
export declare function isDocumentUrl(url: string): boolean;
|
|
6
9
|
export interface PrefetchProps {
|
|
7
10
|
/**
|
|
8
11
|
* Controls how early the full segment is prefetched.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefetch-utils.d.ts","sourceRoot":"","sources":["../../src/lib/prefetch-utils.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEnD,KAAK,gBAAgB,GAAG,aAAa,GAAG;IAAE,OAAO,CAAC,EAAE,aAAa,CAAC;IAAC,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"prefetch-utils.d.ts","sourceRoot":"","sources":["../../src/lib/prefetch-utils.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEnD,KAAK,gBAAgB,GAAG,aAAa,GAAG;IAAE,OAAO,CAAC,EAAE,aAAa,CAAC;IAAC,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,CAAA;AAS3F,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,QAE1C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,WAExC;AAgBD,MAAM,WAAW,aAAa;IAC7B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;CAC3B;AAMD,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,GAAG,aAAa,CAc9E;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,WAUrD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB,WAGpD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC,UAAU,iCAsBjE"}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
const documentUrls = new Set();
|
|
2
|
+
function documentKey(url) {
|
|
3
|
+
const target = new URL(url, location.href);
|
|
4
|
+
return target.origin + target.pathname + target.search;
|
|
5
|
+
}
|
|
6
|
+
/** Remember a URL whose route tree request returned something other than a page. */
|
|
7
|
+
export function markDocumentUrl(url) {
|
|
8
|
+
documentUrls.add(documentKey(url));
|
|
9
|
+
}
|
|
10
|
+
export function isDocumentUrl(url) {
|
|
11
|
+
return documentUrls.has(documentKey(url));
|
|
12
|
+
}
|
|
1
13
|
function isClientNavigable(link) {
|
|
2
14
|
if (!link.href ||
|
|
3
15
|
(link.target && link.target !== "_self") ||
|
|
4
16
|
link.origin !== location.origin ||
|
|
5
|
-
link.hasAttribute("download")
|
|
17
|
+
link.hasAttribute("download") ||
|
|
18
|
+
isDocumentUrl(link.href)) {
|
|
6
19
|
return false;
|
|
7
20
|
}
|
|
8
21
|
return true;
|
package/dist/router.d.ts
CHANGED
|
@@ -28,16 +28,12 @@ type CacheInvalidation = {
|
|
|
28
28
|
tags: string[];
|
|
29
29
|
paths: string[];
|
|
30
30
|
};
|
|
31
|
-
/**
|
|
32
|
-
* Router class for programmatic navigation and RSC data management.
|
|
33
|
-
*/
|
|
31
|
+
/** Router class for programmatic navigation and RSC data management. */
|
|
34
32
|
declare class Router {
|
|
35
33
|
private cache;
|
|
36
34
|
private segment;
|
|
37
35
|
constructor(cache: RouterCache, segment?: Segment | null);
|
|
38
|
-
/**
|
|
39
|
-
* Navigate to a URL using pushState.
|
|
40
|
-
*/
|
|
36
|
+
/** Navigate to a URL using pushState. */
|
|
41
37
|
push: (url: string | URL, options?: NavigateOptions) => void;
|
|
42
38
|
/**
|
|
43
39
|
* Set client-side cache hints for the segment provided by the nearest
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAcrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAcrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAczD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAmB,KAAK,WAAW,EAAqB,MAAM,uBAAuB,CAAA;AAC5F,OAAO,KAAK,EAAoB,OAAO,EAA+B,MAAM,uBAAuB,CAAA;AAyCnG,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAC7D,YAAY,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC7B,qEAAqE;IACrE,MAAM,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AASD,eAAO,MAAM,iBAAiB,mDAAoD,CAAA;AAElF,gEAAgE;AAChE,KAAK,iBAAiB,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,C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AM,GAAG,GAAG,UACV,cAAc,uBAEnB,OAAO,CAAC,iBAAiB,CAAC,CAoC5B;IAED,mDAAmD;IACnD,QAAQ,sBAAuB,iBAAiB,KAAG,IAAI,CAItD;IAED;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;;;;;;;;;;;;;;;;OAiBG;IACH,UAAU,YACA,OAAO,GAAG,MAAM,GAAG,GAAG,YACtB,iBAAiB,KACxB,OAAO,CAAC,OAAO,CAAC,CAkClB;IAED;;;;;;OAMG;IACH,aAAa,QACP,MAAM,GAAG,MAAM,EAAE,YACb,iBAAiB,KACxB,OAAO,CAAC,MAAM,CAAC,CAUjB;IAED,sDAAsD;IACtD,OAAO,CAAC,iBAAiB,CA6DxB;CACD;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,WAKxB;AAED,iEAAiE;AACjE,wBAAgB,WAAW,WAQ1B;AAED,qDAAqD;AACrD,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,KAAK,CAAC,CAwBlE;AAED,mDAAmD;AACnD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,CAAC,YAAY,EAAE,iBAAiB,KAAK,IAAI,QAYzF"}
|
package/dist/router.js
CHANGED
|
@@ -12,6 +12,7 @@ import { reloadForDeploymentMismatch } from "./lib/deployment-reload.js";
|
|
|
12
12
|
import { DocumentNavigation, HandledDeploymentMismatch, DeploymentMismatchError, } from "./lib/errors.js";
|
|
13
13
|
import { extractSegmentHints } from "./lib/extract-segment-hints.js";
|
|
14
14
|
import { REBASK_SHELL_HEADER, REBASK_TAIL_HEADER, REBASK_TRAILER_HEADER, REBASK_TREE_HEADER, } from "./lib/ppr/headers.js";
|
|
15
|
+
import { isDocumentUrl, markDocumentUrl } from "./lib/prefetch-utils.js";
|
|
15
16
|
import { getRouteTreeUrl, } from "./lib/route-prediction.js";
|
|
16
17
|
import { segmentEntryKey } from "./lib/router-cache.js";
|
|
17
18
|
import { captureNavigationIntent, isCurrentNavigation, setNextNavigationScroll, } from "./lib/scroll.js";
|
|
@@ -179,9 +180,7 @@ function splitUsedSearch(response) {
|
|
|
179
180
|
used: promise,
|
|
180
181
|
};
|
|
181
182
|
}
|
|
182
|
-
/**
|
|
183
|
-
* Router class for programmatic navigation and RSC data management.
|
|
184
|
-
*/
|
|
183
|
+
/** Router class for programmatic navigation and RSC data management. */
|
|
185
184
|
class Router {
|
|
186
185
|
cache;
|
|
187
186
|
segment;
|
|
@@ -189,12 +188,15 @@ class Router {
|
|
|
189
188
|
this.cache = cache;
|
|
190
189
|
this.segment = segment;
|
|
191
190
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Navigate to a URL using pushState.
|
|
194
|
-
*/
|
|
191
|
+
/** Navigate to a URL using pushState. */
|
|
195
192
|
push = (url, options) => {
|
|
193
|
+
const target = getUrl(url);
|
|
194
|
+
if (isDocumentUrl(target.href)) {
|
|
195
|
+
window.location.assign(target.href);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
196
198
|
setNextNavigationScroll(options?.scroll !== false);
|
|
197
|
-
window.history.pushState({}, "",
|
|
199
|
+
window.history.pushState({}, "", target.href);
|
|
198
200
|
};
|
|
199
201
|
/**
|
|
200
202
|
* Set client-side cache hints for the segment provided by the nearest
|
|
@@ -217,8 +219,13 @@ class Router {
|
|
|
217
219
|
* Navigate to a URL using replaceState.
|
|
218
220
|
*/
|
|
219
221
|
replace = (url, options) => {
|
|
222
|
+
const target = getUrl(url);
|
|
223
|
+
if (isDocumentUrl(target.href)) {
|
|
224
|
+
window.location.replace(target.href);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
220
227
|
setNextNavigationScroll(options?.scroll !== false);
|
|
221
|
-
window.history.replaceState({}, "",
|
|
228
|
+
window.history.replaceState({}, "", target.href);
|
|
222
229
|
};
|
|
223
230
|
/**
|
|
224
231
|
* Fetch the route tree for a URL.
|
|
@@ -246,6 +253,7 @@ class Router {
|
|
|
246
253
|
if (response.headers.get(REBASK_TREE_HEADER) !== "1") {
|
|
247
254
|
if (response.body)
|
|
248
255
|
await response.body.cancel();
|
|
256
|
+
markDocumentUrl(url);
|
|
249
257
|
throw new DocumentNavigation();
|
|
250
258
|
}
|
|
251
259
|
this.cache.handleDeploymentMismatch(response, url, "tree");
|
|
@@ -561,6 +569,8 @@ class Router {
|
|
|
561
569
|
* Set to `false` to bypass dedup and force a fresh request.
|
|
562
570
|
*/
|
|
563
571
|
prefetchRouteTree = async (url, cache = true, dedupe = true) => {
|
|
572
|
+
if (isDocumentUrl(url))
|
|
573
|
+
throw new DocumentNavigation();
|
|
564
574
|
const isCurrent = this.cache.captureRouteTransaction();
|
|
565
575
|
if (cache) {
|
|
566
576
|
// Check if already fully cached
|