Skip to content

Commit 528ce1d

Browse files
committed
run load functions with owner of router component
1 parent 76b2689 commit 528ce1d

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

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)