@solidjs/router 0.12.0 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data/cache.js +17 -13
- package/dist/index.js +21 -14
- package/dist/routers/components.jsx +4 -2
- package/dist/routing.d.ts +1 -1
- package/dist/routing.js +6 -4
- package/package.json +1 -1
package/dist/data/cache.js
CHANGED
|
@@ -87,8 +87,8 @@ export function cache(fn, name) {
|
|
|
87
87
|
let res = cached[1];
|
|
88
88
|
if (intent !== "preload") {
|
|
89
89
|
res =
|
|
90
|
-
"then" in
|
|
91
|
-
?
|
|
90
|
+
"then" in cached[1]
|
|
91
|
+
? cached[1].then(handleResponse(false), handleResponse(true))
|
|
92
92
|
: handleResponse(false)(cached[1]);
|
|
93
93
|
!isServer && intent === "navigate" && startTransition(() => cached[3][1](cached[0])); // update version
|
|
94
94
|
}
|
|
@@ -97,15 +97,6 @@ export function cache(fn, name) {
|
|
|
97
97
|
let res = !isServer && sharedConfig.context && sharedConfig.has(key)
|
|
98
98
|
? sharedConfig.load(key) // hydrating
|
|
99
99
|
: fn(...args);
|
|
100
|
-
// serialize on server
|
|
101
|
-
if (isServer &&
|
|
102
|
-
sharedConfig.context &&
|
|
103
|
-
sharedConfig.context.async &&
|
|
104
|
-
!sharedConfig.context.noHydrate) {
|
|
105
|
-
const e = getRequestEvent();
|
|
106
|
-
e && e.router.dataOnly && (e.router.data[key] = res);
|
|
107
|
-
(!e || !e.serverOnly) && sharedConfig.context.serialize(key, res);
|
|
108
|
-
}
|
|
109
100
|
if (cached) {
|
|
110
101
|
cached[0] = now;
|
|
111
102
|
cached[1] = res;
|
|
@@ -120,12 +111,25 @@ export function cache(fn, name) {
|
|
|
120
111
|
cached[3].count++;
|
|
121
112
|
cached[3][0](); // track
|
|
122
113
|
}
|
|
114
|
+
if (isServer) {
|
|
115
|
+
const e = getRequestEvent();
|
|
116
|
+
e && e.router.dataOnly && (e.router.data[key] = res);
|
|
117
|
+
return res;
|
|
118
|
+
}
|
|
123
119
|
if (intent !== "preload") {
|
|
124
120
|
res =
|
|
125
|
-
"then" in
|
|
126
|
-
?
|
|
121
|
+
"then" in res
|
|
122
|
+
? res.then(handleResponse(false), handleResponse(true))
|
|
127
123
|
: handleResponse(false)(res);
|
|
128
124
|
}
|
|
125
|
+
// serialize on server
|
|
126
|
+
if (isServer &&
|
|
127
|
+
sharedConfig.context &&
|
|
128
|
+
sharedConfig.context.async &&
|
|
129
|
+
!sharedConfig.context.noHydrate) {
|
|
130
|
+
const e = getRequestEvent();
|
|
131
|
+
(!e || !e.serverOnly) && sharedConfig.context.serialize(key, res);
|
|
132
|
+
}
|
|
129
133
|
return res;
|
|
130
134
|
function handleResponse(error) {
|
|
131
135
|
return async (v) => {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isServer, getRequestEvent, createComponent as createComponent$1, delegateEvents, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
1
|
+
import { isServer, getRequestEvent, createComponent as createComponent$1, memo, delegateEvents, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
2
2
|
import { getOwner, runWithOwner, createMemo, createContext, onCleanup, useContext, untrack, createSignal, createRenderEffect, on, startTransition, resetErrorBoundaries, createComponent, children, mergeProps, createRoot, Show, getListener, sharedConfig, $TRACK, splitProps, createResource } from 'solid-js';
|
|
3
3
|
import { createStore, reconcile, unwrap } from 'solid-js/store';
|
|
4
4
|
|
|
@@ -406,7 +406,7 @@ let intent;
|
|
|
406
406
|
function getIntent() {
|
|
407
407
|
return intent;
|
|
408
408
|
}
|
|
409
|
-
function createRouterContext(integration, getBranches, options = {}) {
|
|
409
|
+
function createRouterContext(integration, getContext, getBranches, options = {}) {
|
|
410
410
|
const {
|
|
411
411
|
signal: [source, setSource],
|
|
412
412
|
utils = {}
|
|
@@ -577,7 +577,10 @@ function createRouterContext(integration, getBranches, options = {}) {
|
|
|
577
577
|
params
|
|
578
578
|
} = matches[match];
|
|
579
579
|
route.component && route.component.preload && route.component.preload();
|
|
580
|
-
|
|
580
|
+
const {
|
|
581
|
+
load
|
|
582
|
+
} = route;
|
|
583
|
+
preloadData && load && runWithOwner(getContext(), () => load({
|
|
581
584
|
params,
|
|
582
585
|
location: {
|
|
583
586
|
pathname: url.pathname,
|
|
@@ -588,7 +591,7 @@ function createRouterContext(integration, getBranches, options = {}) {
|
|
|
588
591
|
key: ""
|
|
589
592
|
},
|
|
590
593
|
intent: "preload"
|
|
591
|
-
});
|
|
594
|
+
}));
|
|
592
595
|
}
|
|
593
596
|
intent = prevIntent;
|
|
594
597
|
}
|
|
@@ -644,7 +647,8 @@ const createRouterComponent = router => props => {
|
|
|
644
647
|
load: props.rootLoad,
|
|
645
648
|
children: routeDefs()
|
|
646
649
|
} : routeDefs(), props.base || ""));
|
|
647
|
-
|
|
650
|
+
let context;
|
|
651
|
+
const routerState = createRouterContext(router, () => context, branches, {
|
|
648
652
|
base,
|
|
649
653
|
singleFlight: props.singleFlight
|
|
650
654
|
});
|
|
@@ -652,12 +656,12 @@ const createRouterComponent = router => props => {
|
|
|
652
656
|
return createComponent$1(RouterContextObj.Provider, {
|
|
653
657
|
value: routerState,
|
|
654
658
|
get children() {
|
|
655
|
-
return createComponent$1(Routes, {
|
|
659
|
+
return [memo(() => (context = getOwner()) && null), createComponent$1(Routes, {
|
|
656
660
|
routerState: routerState,
|
|
657
661
|
get branches() {
|
|
658
662
|
return branches();
|
|
659
663
|
}
|
|
660
|
-
});
|
|
664
|
+
})];
|
|
661
665
|
}
|
|
662
666
|
});
|
|
663
667
|
};
|
|
@@ -926,13 +930,6 @@ function cache(fn, name) {
|
|
|
926
930
|
}
|
|
927
931
|
let res = !isServer && sharedConfig.context && sharedConfig.has(key) ? sharedConfig.load(key) // hydrating
|
|
928
932
|
: fn(...args);
|
|
929
|
-
|
|
930
|
-
// serialize on server
|
|
931
|
-
if (isServer && sharedConfig.context && sharedConfig.context.async && !sharedConfig.context.noHydrate) {
|
|
932
|
-
const e = getRequestEvent();
|
|
933
|
-
e && e.router.dataOnly && (e.router.data[key] = res);
|
|
934
|
-
(!e || !e.serverOnly) && sharedConfig.context.serialize(key, res);
|
|
935
|
-
}
|
|
936
933
|
if (cached) {
|
|
937
934
|
cached[0] = now;
|
|
938
935
|
cached[1] = res;
|
|
@@ -946,9 +943,19 @@ function cache(fn, name) {
|
|
|
946
943
|
cached[3].count++;
|
|
947
944
|
cached[3][0](); // track
|
|
948
945
|
}
|
|
946
|
+
if (isServer) {
|
|
947
|
+
const e = getRequestEvent();
|
|
948
|
+
e && e.router.dataOnly && (e.router.data[key] = res);
|
|
949
|
+
return res;
|
|
950
|
+
}
|
|
949
951
|
if (intent !== "preload") {
|
|
950
952
|
res = "then" in res ? res.then(handleResponse(false), handleResponse(true)) : handleResponse(false)(res);
|
|
951
953
|
}
|
|
954
|
+
// serialize on server
|
|
955
|
+
if (isServer && sharedConfig.context && sharedConfig.context.async && !sharedConfig.context.noHydrate) {
|
|
956
|
+
const e = getRequestEvent();
|
|
957
|
+
(!e || !e.serverOnly) && sharedConfig.context.serialize(key, res);
|
|
958
|
+
}
|
|
952
959
|
return res;
|
|
953
960
|
function handleResponse(error) {
|
|
954
961
|
return async v => {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/*@refresh skip*/
|
|
2
2
|
import { getRequestEvent, isServer } from "solid-js/web";
|
|
3
|
-
import { children, createMemo, createRoot, mergeProps, on, Show } from "solid-js";
|
|
3
|
+
import { children, createMemo, createRoot, getOwner, mergeProps, on, Show } from "solid-js";
|
|
4
4
|
import { createBranches, createRouteContext, createRouterContext, getRouteMatches, RouteContextObj, RouterContextObj } from "../routing.js";
|
|
5
5
|
import { createMemoObject, extractSearchParams } from "../utils.js";
|
|
6
6
|
export const createRouterComponent = (router) => (props) => {
|
|
7
7
|
const { base } = props;
|
|
8
8
|
const routeDefs = children(() => props.children);
|
|
9
9
|
const branches = createMemo(() => createBranches(props.root ? { component: props.root, load: props.rootLoad, children: routeDefs() } : routeDefs(), props.base || ""));
|
|
10
|
-
|
|
10
|
+
let context;
|
|
11
|
+
const routerState = createRouterContext(router, () => context, branches, { base, singleFlight: props.singleFlight });
|
|
11
12
|
router.create && router.create(routerState);
|
|
12
13
|
return (<RouterContextObj.Provider value={routerState}>
|
|
14
|
+
{(context = getOwner()) && null}
|
|
13
15
|
<Routes routerState={routerState} branches={branches()}/>
|
|
14
16
|
</RouterContextObj.Provider>);
|
|
15
17
|
};
|
package/dist/routing.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function createBranches(routeDef: RouteDefinition | RouteDefiniti
|
|
|
19
19
|
export declare function getRouteMatches(branches: Branch[], location: string): RouteMatch[];
|
|
20
20
|
export declare function createLocation(path: Accessor<string>, state: Accessor<any>): Location;
|
|
21
21
|
export declare function getIntent(): Intent | undefined;
|
|
22
|
-
export declare function createRouterContext(integration: RouterIntegration, getBranches?: () => Branch[], options?: {
|
|
22
|
+
export declare function createRouterContext(integration: RouterIntegration, getContext?: () => any, getBranches?: () => Branch[], options?: {
|
|
23
23
|
base?: string;
|
|
24
24
|
singleFlight?: boolean;
|
|
25
25
|
}): RouterContext;
|
package/dist/routing.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runWithOwner } from "solid-js";
|
|
1
2
|
import { createComponent, createContext, createMemo, createRenderEffect, createSignal, on, onCleanup, untrack, useContext, startTransition, resetErrorBoundaries } from "solid-js";
|
|
2
3
|
import { isServer, getRequestEvent } from "solid-js/web";
|
|
3
4
|
import { createBeforeLeave } from "./lifecycle.js";
|
|
@@ -183,7 +184,7 @@ let intent;
|
|
|
183
184
|
export function getIntent() {
|
|
184
185
|
return intent;
|
|
185
186
|
}
|
|
186
|
-
export function createRouterContext(integration, getBranches, options = {}) {
|
|
187
|
+
export function createRouterContext(integration, getContext, getBranches, options = {}) {
|
|
187
188
|
const { signal: [source, setSource], utils = {} } = integration;
|
|
188
189
|
const parsePath = utils.parsePath || (p => p);
|
|
189
190
|
const renderPath = utils.renderPath || (p => p);
|
|
@@ -331,9 +332,10 @@ export function createRouterContext(integration, getBranches, options = {}) {
|
|
|
331
332
|
route.component &&
|
|
332
333
|
route.component.preload &&
|
|
333
334
|
route.component.preload();
|
|
335
|
+
const { load } = route;
|
|
334
336
|
preloadData &&
|
|
335
|
-
|
|
336
|
-
|
|
337
|
+
load &&
|
|
338
|
+
runWithOwner(getContext(), () => load({
|
|
337
339
|
params,
|
|
338
340
|
location: {
|
|
339
341
|
pathname: url.pathname,
|
|
@@ -344,7 +346,7 @@ export function createRouterContext(integration, getBranches, options = {}) {
|
|
|
344
346
|
key: ""
|
|
345
347
|
},
|
|
346
348
|
intent: "preload"
|
|
347
|
-
});
|
|
349
|
+
}));
|
|
348
350
|
}
|
|
349
351
|
intent = prevIntent;
|
|
350
352
|
}
|