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
Copy file name to clipboardExpand all lines: documentation/docs/20-core-concepts/20-load.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,7 +172,7 @@ A `load` function is invoked at runtime, unless you [prerender](page-options#pre
172
172
173
173
### Input
174
174
175
-
Both universal and server `load` functions have access to properties describing the request (`params`, `route` and `url`) and various functions (`fetch`, `setHeaders`, `parent`and `depends`). These are described in the following sections.
175
+
Both universal and server `load` functions have access to properties describing the request (`params`, `route` and `url`) and various functions (`fetch`, `setHeaders`, `parent`, `depends`and `untrack`). These are described in the following sections.
176
176
177
177
Server `load` functions are called with a `ServerLoadEvent`, which inherits `clientAddress`, `cookies`, `locals`, `platform` and `request` from `RequestEvent`.
178
178
@@ -574,6 +574,20 @@ Dependency tracking does not apply _after_ the `load` function has returned —
574
574
575
575
Search parameters are tracked independently from the rest of the url. For example, accessing `event.url.searchParams.get("x")` inside a `load` function will make that `load` function re-run when navigating from `?x=1` to `?x=2`, but not when navigating from `?x=1&y=1` to `?x=1&y=2`.
576
576
577
+
### Untracking dependencies
578
+
579
+
In rare cases, you may wish to exclude something from the dependency tracking mechanism. You can do this with the provided `untrack` function:
580
+
581
+
```js
582
+
/// file: src/routes/+page.js
583
+
exportasyncfunctionload({ untrack, url }) {
584
+
// Untrack url.pathname so that path changes don't trigger a rerun
585
+
if (untrack(() =>url.pathname==='/')) {
586
+
return { message:'Welcome!' };
587
+
}
588
+
}
589
+
```
590
+
577
591
### Manual invalidation
578
592
579
593
You can also rerun `load` functions that apply to the current page using [`invalidate(url)`](modules#$app-navigation-invalidate), which reruns all `load` functions that depend on `url`, and [`invalidateAll()`](modules#$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.
0 commit comments