You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add option to `invalidate` to not reset `page.state` (we don't want to
add `refresh` for this as we may want to introduce it in relation to
queries and not for load functions)
- Deprecated `invalidateAll` in favor of `refreshAll` (also on `goto`)
- Removed the `includeLoadFunctions` option from `refreshAll` - it now
always reruns `load` functions
Closes#11783Closes#13139
---------
Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
You can also rerun `load` functions that apply to the current page using [`invalidate(url)`]($app-navigation#invalidate), which reruns all `load` functions that depend on `url`, and [`invalidateAll()`]($app-navigation#invalidateAll), which reruns every `load` function. Server load functions will never automatically depend on a fetched `url` to avoid leaking secrets to the client.
641
+
You can also rerun `load` functions that apply to the current page using [`invalidate(url)`]($app-navigation#invalidate), which reruns all `load` functions that depend on `url`, and [`refreshAll()`]($app-navigation#refreshAll), which reruns every `load` function and all active queries. Server load functions will never automatically depend on a fetched `url` to avoid leaking secrets to the client.
642
+
643
+
> [!NOTE]`refreshAll` does _not_ reset `page.state`, unlike its deprecated predecessor `invalidateAll`.
642
644
643
645
A `load` function depends on `url` if it calls `fetch(url)` or `depends(url)`. Note that `url` can be a custom identifier that starts with `[a-z]:`:
@@ -689,7 +691,7 @@ To summarize, a `load` function will rerun in the following situations:
689
691
- It calls `await parent()` and a parent `load` function reran
690
692
- A child `load` function calls `await parent()` and is rerunning, and the parent is a server load function
691
693
- It declared a dependency on a specific URL via [`fetch`](#Making-fetch-requests) (universal load only) or [`depends`](@sveltejs-kit#LoadEvent), and that URL was marked invalid with [`invalidate(url)`]($app-navigation#invalidate)
692
-
- All active `load` functions were forcibly rerun with [`invalidateAll()`]($app-navigation#invalidateAll)
694
+
- All active `load` functions were forcibly rerun with [`refreshAll()`]($app-navigation#refreshAll)
693
695
694
696
`params` and `url` can change in response to a `<a href="..">` link click, a [`<form>` interaction](form-actions#GET-vs-POST), a [`goto`]($app-navigation#goto) invocation, or a [`redirect`](@sveltejs-kit#redirect).
// TODO the ticks shouldn't be necessary, something inside Svelte itself is buggy
598
594
// when a query in a layout that still exists after page change is refreshed earlier than this
599
595
voidsvelte
@@ -2322,6 +2318,8 @@ export function disableScrollHandling() {
2322
2318
}
2323
2319
}
2324
2320
2321
+
letwarned_on_invalidate_all=false;
2322
+
2325
2323
/**
2326
2324
* Allows you to navigate programmatically to a given route, with options such as keeping the current element focused.
2327
2325
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
@@ -2335,8 +2333,9 @@ export function disableScrollHandling() {
2335
2333
* @param {boolean} [opts.replaceState] If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
2336
2334
* @param {boolean} [opts.noScroll] If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation
2337
2335
* @param {boolean} [opts.keepFocus] If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body
2338
-
* @param {boolean} [opts.invalidateAll] If `true`, all `load` functions of the page will be rerun. See https://svelte.dev/docs/kit/load#rerunning-load-functions for more info on invalidation.
2336
+
* @param {boolean} [opts.refreshAll] If `true`, all `load` functions and queries of the page will be rerun. See https://svelte.dev/docs/kit/load#rerunning-load-functions for more info on invalidation.
2339
2337
* @param {Array<string | URL | ((url: URL) => boolean)>} [opts.invalidate] Causes any load functions to re-run if they depend on one of the urls
2338
+
* @param {boolean} [opts.invalidateAll] Deprecated in favour of opts.refreshAll.
2340
2339
* @param {App.PageState} [opts.state] An optional object that will be available as `page.state`
* @param {boolean} [keepState] If `true`, the current `page.state` will be preserved. Otherwise, it will be reset to an empty object. `false` by default.
thrownewError('Cannot call invalidate(...) on the server');
2392
2400
}
2393
2401
2394
2402
push_invalidated(resource);
2395
2403
2396
-
return_invalidate();
2404
+
return_invalidate(!keepState);
2397
2405
}
2398
2406
2399
2407
/**
@@ -2410,6 +2418,10 @@ function push_invalidated(resource) {
2410
2418
2411
2419
/**
2412
2420
* Causes all `load` and `query` functions belonging to the currently active page to re-run. Returns a `Promise` that resolves when the page is subsequently updated.
2421
+
*
2422
+
* Note that this resets `page.state` to an empty object. If you want to preserve `page.state` (for example when using [shallow routing](https://svelte.dev/docs/kit/shallow-routing)), use `refreshAll` instead.
2423
+
*
2424
+
* @deprecated Use [`refreshAll`](https://svelte.dev/docs/kit/$app-navigation#refreshAll) instead. Unlike `invalidateAll`, `refreshAll` does not reset `page.state`.
2413
2425
* @returns {Promise<void>}
2414
2426
*/
2415
2427
exportfunctioninvalidateAll(){
@@ -2422,18 +2434,17 @@ export function invalidateAll() {
2422
2434
}
2423
2435
2424
2436
/**
2425
-
* Causes all currently active remote functions to refresh, and all `load` functions belonging to the currently active page to re-run (unless disabled via the option argument).
2437
+
* Causes all currently active remote functions to refresh, and all `load` functions belonging to the currently active page to re-run.
2426
2438
* Returns a `Promise` that resolves when the page is subsequently updated.
0 commit comments