Skip to content

Commit 5391fbb

Browse files
authored
Merge pull request #376 from Brendonovich/main
Run load functions with owner & context of `Router` component.
2 parents 6d0be9e + 052d385 commit 5391fbb

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

.changeset/spicy-hornets-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
Run load functions with owner & context of `Router` component.

src/routing.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JSX, Accessor } from "solid-js";
1+
import { JSX, Accessor, getOwner, runWithOwner } from "solid-js";
22
import {
33
createComponent,
44
createContext,
@@ -330,6 +330,8 @@ export function createRouterContext(
330330
});
331331
});
332332

333+
const owner = getOwner();
334+
333335
return {
334336
base: baseRoute,
335337
location,
@@ -440,20 +442,23 @@ export function createRouterContext(
440442
route.component &&
441443
(route.component as MaybePreloadableComponent).preload &&
442444
(route.component as MaybePreloadableComponent).preload!();
445+
const { load } = route;
443446
preloadData &&
444-
route.load &&
445-
route.load({
446-
params,
447-
location: {
448-
pathname: url.pathname,
449-
search: url.search,
450-
hash: url.hash,
451-
query: extractSearchParams(url),
452-
state: null,
453-
key: ""
454-
},
455-
intent: "preload"
456-
});
447+
load &&
448+
runWithOwner(owner, () =>
449+
load({
450+
params,
451+
location: {
452+
pathname: url.pathname,
453+
search: url.search,
454+
hash: url.hash,
455+
query: extractSearchParams(url),
456+
state: null,
457+
key: ""
458+
},
459+
intent: "preload"
460+
})
461+
);
457462
}
458463
intent = prevIntent;
459464
}

0 commit comments

Comments
 (0)