@sveltejs/kit 1.0.0-next.460 → 1.0.0-next.461
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/package.json
CHANGED
|
@@ -16,6 +16,7 @@ export const disableScrollHandling = ssr
|
|
|
16
16
|
: client.disable_scroll_handling;
|
|
17
17
|
export const goto = ssr ? guard('goto') : client.goto;
|
|
18
18
|
export const invalidate = ssr ? guard('invalidate') : client.invalidate;
|
|
19
|
+
export const invalidateAll = ssr ? guard('invalidateAll') : client.invalidateAll;
|
|
19
20
|
export const prefetch = ssr ? guard('prefetch') : client.prefetch;
|
|
20
21
|
export const prefetchRoutes = ssr ? guard('prefetchRoutes') : client.prefetch_routes;
|
|
21
22
|
export const beforeNavigate = ssr ? () => {} : client.before_navigate;
|
|
@@ -70,7 +70,7 @@ function check_for_removed_attributes() {
|
|
|
70
70
|
* @returns {import('./types').Client}
|
|
71
71
|
*/
|
|
72
72
|
export function create_client({ target, base, trailing_slash }) {
|
|
73
|
-
/** @type {Array<((
|
|
73
|
+
/** @type {Array<((url: URL) => boolean)>} */
|
|
74
74
|
const invalidated = [];
|
|
75
75
|
|
|
76
76
|
/** @type {{id: string | null, promise: Promise<import('./types').NavigationResult | undefined> | null}} */
|
|
@@ -103,6 +103,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
103
103
|
|
|
104
104
|
/** @type {Promise<void> | null} */
|
|
105
105
|
let invalidating = null;
|
|
106
|
+
let force_invalidation = false;
|
|
106
107
|
|
|
107
108
|
/** @type {import('svelte').SvelteComponent} */
|
|
108
109
|
let root;
|
|
@@ -139,6 +140,19 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
139
140
|
/** @type {{}} */
|
|
140
141
|
let token;
|
|
141
142
|
|
|
143
|
+
function invalidate() {
|
|
144
|
+
if (!invalidating) {
|
|
145
|
+
invalidating = Promise.resolve().then(async () => {
|
|
146
|
+
await update(new URL(location.href), []);
|
|
147
|
+
|
|
148
|
+
invalidating = null;
|
|
149
|
+
force_invalidation = false;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return invalidating;
|
|
154
|
+
}
|
|
155
|
+
|
|
142
156
|
/**
|
|
143
157
|
* @param {string | URL} url
|
|
144
158
|
* @param {{ noscroll?: boolean; replaceState?: boolean; keepfocus?: boolean; state?: any }} opts
|
|
@@ -639,6 +653,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
639
653
|
* @param {{ url: boolean, params: string[] }} changed
|
|
640
654
|
*/
|
|
641
655
|
function has_changed(changed, parent_changed, uses) {
|
|
656
|
+
if (force_invalidation) return true;
|
|
657
|
+
|
|
642
658
|
if (!uses) return false;
|
|
643
659
|
|
|
644
660
|
if (uses.parent && parent_changed) return true;
|
|
@@ -648,8 +664,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
648
664
|
if (uses.params.has(param)) return true;
|
|
649
665
|
}
|
|
650
666
|
|
|
651
|
-
for (const
|
|
652
|
-
if (invalidated.some((fn) => fn(
|
|
667
|
+
for (const href of uses.dependencies) {
|
|
668
|
+
if (invalidated.some((fn) => fn(new URL(href)))) return true;
|
|
653
669
|
}
|
|
654
670
|
|
|
655
671
|
return false;
|
|
@@ -1057,28 +1073,25 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1057
1073
|
|
|
1058
1074
|
invalidate: (resource) => {
|
|
1059
1075
|
if (resource === undefined) {
|
|
1060
|
-
//
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1076
|
+
// TODO remove for 1.0
|
|
1077
|
+
throw new Error(
|
|
1078
|
+
'`invalidate()` (with no arguments) has been replaced by `invalidateAll()`'
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
if (typeof resource === 'function') {
|
|
1067
1083
|
invalidated.push(resource);
|
|
1068
1084
|
} else {
|
|
1069
1085
|
const { href } = new URL(resource, location.href);
|
|
1070
|
-
invalidated.push((
|
|
1086
|
+
invalidated.push((url) => url.href === href);
|
|
1071
1087
|
}
|
|
1072
1088
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
await update(new URL(location.href), []);
|
|
1076
|
-
|
|
1077
|
-
invalidating = null;
|
|
1078
|
-
});
|
|
1079
|
-
}
|
|
1089
|
+
return invalidate();
|
|
1090
|
+
},
|
|
1080
1091
|
|
|
1081
|
-
|
|
1092
|
+
invalidateAll: () => {
|
|
1093
|
+
force_invalidation = true;
|
|
1094
|
+
return invalidate();
|
|
1082
1095
|
},
|
|
1083
1096
|
|
|
1084
1097
|
prefetch: async (href) => {
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
beforeNavigate,
|
|
4
4
|
goto,
|
|
5
5
|
invalidate,
|
|
6
|
+
invalidateAll,
|
|
6
7
|
prefetch,
|
|
7
8
|
prefetchRoutes
|
|
8
9
|
} from '$app/navigation';
|
|
@@ -17,6 +18,7 @@ export interface Client {
|
|
|
17
18
|
disable_scroll_handling: () => void;
|
|
18
19
|
goto: typeof goto;
|
|
19
20
|
invalidate: typeof invalidate;
|
|
21
|
+
invalidateAll: typeof invalidateAll;
|
|
20
22
|
prefetch: typeof prefetch;
|
|
21
23
|
prefetch_routes: typeof prefetchRoutes;
|
|
22
24
|
|
|
@@ -194,8 +194,8 @@ export function handle_fatal_error(event, options, error) {
|
|
|
194
194
|
|
|
195
195
|
// ideally we'd use sec-fetch-dest instead, but Safari — quelle surprise — doesn't support it
|
|
196
196
|
const type = negotiate(event.request.headers.get('accept') || 'text/html', [
|
|
197
|
-
'
|
|
198
|
-
'
|
|
197
|
+
'application/json',
|
|
198
|
+
'text/html'
|
|
199
199
|
]);
|
|
200
200
|
|
|
201
201
|
if (event.url.pathname.endsWith(DATA_SUFFIX) || type === 'application/json') {
|
package/types/ambient.d.ts
CHANGED
|
@@ -113,10 +113,25 @@ declare module '$app/navigation' {
|
|
|
113
113
|
opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any }
|
|
114
114
|
): Promise<void>;
|
|
115
115
|
/**
|
|
116
|
-
* Causes any `load` functions belonging to the currently active page to re-run if they
|
|
117
|
-
*
|
|
116
|
+
* Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
117
|
+
*
|
|
118
|
+
* If the argument is given as a `string` or `URL`, it must resolve to the same URL that was passed to `fetch` or `depends` (including query parameters).
|
|
119
|
+
* To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
|
|
120
|
+
*
|
|
121
|
+
* The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
|
|
122
|
+
* This can be useful if you want to invalidate based on a pattern instead of a exact match.
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* // Example: Match '/path' regardless of the query parameters
|
|
126
|
+
* invalidate((url) => url.pathname === '/path');
|
|
127
|
+
* ```
|
|
128
|
+
* @param url The invalidated URL
|
|
129
|
+
*/
|
|
130
|
+
export function invalidate(url: string | URL | ((url: URL) => boolean)): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Causes all `load` functions belonging to the currently active page to re-run. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
118
133
|
*/
|
|
119
|
-
export function
|
|
134
|
+
export function invalidateAll(): Promise<void>;
|
|
120
135
|
/**
|
|
121
136
|
* Programmatically prefetches the given page, which means
|
|
122
137
|
* 1. ensuring that the code for the page is loaded, and
|