Skip to content

Commit 66ade96

Browse files
committed
untrack docs
1 parent ad7f045 commit 66ade96

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

documentation/docs/20-core-concepts/20-load.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ A `load` function is invoked at runtime, unless you [prerender](page-options#pre
172172

173173
### Input
174174

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.
176176

177177
Server `load` functions are called with a `ServerLoadEvent`, which inherits `clientAddress`, `cookies`, `locals`, `platform` and `request` from `RequestEvent`.
178178

@@ -574,6 +574,20 @@ Dependency tracking does not apply _after_ the `load` function has returned —
574574

575575
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`.
576576

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+
export async function load({ 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+
577591
### Manual invalidation
578592

579593
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

Comments
 (0)