@solidjs/router 0.14.8 → 0.14.9

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.
@@ -184,7 +184,7 @@ cache.set = (key, value) => {
184
184
  cache.clear = () => getCache().clear();
185
185
  function matchKey(key, keys) {
186
186
  for (let k of keys) {
187
- if (key.startsWith(k))
187
+ if (k && key.startsWith(k))
188
188
  return true;
189
189
  }
190
190
  return false;
@@ -59,7 +59,7 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
59
59
  return;
60
60
  const [a, url] = res;
61
61
  transformUrl && (url.pathname = transformUrl(url.pathname));
62
- router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" });
62
+ router.preloadRoute(url, a.getAttribute("preload") !== "false");
63
63
  }
64
64
  function handleAnchorMove(evt) {
65
65
  clearTimeout(preloadTimeout);
@@ -71,7 +71,7 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
71
71
  return;
72
72
  transformUrl && (url.pathname = transformUrl(url.pathname));
73
73
  preloadTimeout = setTimeout(() => {
74
- router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" });
74
+ router.preloadRoute(url, a.getAttribute("preload") !== "false");
75
75
  lastElement = a;
76
76
  }, 20);
77
77
  }
@@ -12,7 +12,7 @@ export function redirect(url, init = 302) {
12
12
  }
13
13
  const headers = new Headers(responseInit.headers);
14
14
  headers.set("Location", url);
15
- revalidate && headers.set("X-Revalidate", revalidate.toString());
15
+ revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
16
16
  const response = new Response(null, {
17
17
  ...responseInit,
18
18
  headers: headers
@@ -22,7 +22,7 @@ export function redirect(url, init = 302) {
22
22
  export function reload(init = {}) {
23
23
  const { revalidate, ...responseInit } = init;
24
24
  const headers = new Headers(responseInit.headers);
25
- revalidate && headers.set("X-Revalidate", revalidate.toString());
25
+ revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
26
26
  return new Response(null, {
27
27
  ...responseInit,
28
28
  headers
@@ -31,7 +31,7 @@ export function reload(init = {}) {
31
31
  export function json(data, init = {}) {
32
32
  const { revalidate, ...responseInit } = init;
33
33
  const headers = new Headers(responseInit.headers);
34
- revalidate && headers.set("X-Revalidate", revalidate.toString());
34
+ revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
35
35
  headers.set("Content-Type", "application/json");
36
36
  const response = new Response(JSON.stringify(data), {
37
37
  ...responseInit,
package/dist/index.js CHANGED
@@ -244,7 +244,10 @@ const useHref = to => {
244
244
  const useNavigate = () => useRouter().navigatorFactory();
245
245
  const useLocation = () => useRouter().location;
246
246
  const useIsRouting = () => useRouter().isRouting;
247
- const usePreloadRoute = () => useRouter().preloadRoute;
247
+ const usePreloadRoute = () => {
248
+ const pre = useRouter().preloadRoute;
249
+ return (url, options = {}) => pre(url instanceof URL ? url : new URL(url, mockBase), options.preloadData);
250
+ };
248
251
  const useMatch = (path, matchFilters) => {
249
252
  const location = useLocation();
250
253
  const matchers = createMemo(() => expandOptionals(path()).map(path => createMatcher(path, undefined, matchFilters)));
@@ -585,7 +588,7 @@ function createRouterContext(integration, branches, getContext, options = {}) {
585
588
  referrers.length = 0;
586
589
  }
587
590
  }
588
- function preloadRoute(url, options = {}) {
591
+ function preloadRoute(url, preloadData) {
589
592
  const matches = getRouteMatches(branches(), url.pathname);
590
593
  const prevIntent = intent;
591
594
  intent = "preload";
@@ -599,7 +602,7 @@ function createRouterContext(integration, branches, getContext, options = {}) {
599
602
  preload
600
603
  } = route;
601
604
  inPreloadFn = true;
602
- options.preloadData && preload && runWithOwner(getContext(), () => preload({
605
+ preloadData && preload && runWithOwner(getContext(), () => preload({
603
606
  params,
604
607
  location: {
605
608
  pathname: url.pathname,
@@ -1032,7 +1035,7 @@ cache.set = (key, value) => {
1032
1035
  cache.clear = () => getCache().clear();
1033
1036
  function matchKey(key, keys) {
1034
1037
  for (let k of keys) {
1035
- if (key.startsWith(k)) return true;
1038
+ if (k && key.startsWith(k)) return true;
1036
1039
  }
1037
1040
  return false;
1038
1041
  }
@@ -1226,9 +1229,7 @@ function setupNativeEvents(preload = true, explicitLinks = false, actionBase = "
1226
1229
  if (!res) return;
1227
1230
  const [a, url] = res;
1228
1231
  transformUrl && (url.pathname = transformUrl(url.pathname));
1229
- router.preloadRoute(url, {
1230
- preloadData: a.getAttribute("preload") !== "false"
1231
- });
1232
+ router.preloadRoute(url, a.getAttribute("preload") !== "false");
1232
1233
  }
1233
1234
  function handleAnchorMove(evt) {
1234
1235
  clearTimeout(preloadTimeout);
@@ -1238,9 +1239,7 @@ function setupNativeEvents(preload = true, explicitLinks = false, actionBase = "
1238
1239
  if (lastElement === a) return;
1239
1240
  transformUrl && (url.pathname = transformUrl(url.pathname));
1240
1241
  preloadTimeout = setTimeout(() => {
1241
- router.preloadRoute(url, {
1242
- preloadData: a.getAttribute("preload") !== "false"
1243
- });
1242
+ router.preloadRoute(url, a.getAttribute("preload") !== "false");
1244
1243
  lastElement = a;
1245
1244
  }, 20);
1246
1245
  }
@@ -1612,7 +1611,7 @@ function redirect(url, init = 302) {
1612
1611
  }
1613
1612
  const headers = new Headers(responseInit.headers);
1614
1613
  headers.set("Location", url);
1615
- revalidate && headers.set("X-Revalidate", revalidate.toString());
1614
+ revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
1616
1615
  const response = new Response(null, {
1617
1616
  ...responseInit,
1618
1617
  headers: headers
@@ -1625,7 +1624,7 @@ function reload(init = {}) {
1625
1624
  ...responseInit
1626
1625
  } = init;
1627
1626
  const headers = new Headers(responseInit.headers);
1628
- revalidate && headers.set("X-Revalidate", revalidate.toString());
1627
+ revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
1629
1628
  return new Response(null, {
1630
1629
  ...responseInit,
1631
1630
  headers
@@ -1637,7 +1636,7 @@ function json(data, init = {}) {
1637
1636
  ...responseInit
1638
1637
  } = init;
1639
1638
  const headers = new Headers(responseInit.headers);
1640
- revalidate && headers.set("X-Revalidate", revalidate.toString());
1639
+ revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
1641
1640
  headers.set("Content-Type", "application/json");
1642
1641
  const response = new Response(JSON.stringify(data), {
1643
1642
  ...responseInit,
package/dist/routing.d.ts CHANGED
@@ -9,8 +9,8 @@ export declare const useHref: (to: () => string | undefined) => Accessor<string
9
9
  export declare const useNavigate: () => Navigator;
10
10
  export declare const useLocation: <S = unknown>() => Location<S>;
11
11
  export declare const useIsRouting: () => () => boolean;
12
- export declare const usePreloadRoute: () => (url: URL, options: {
13
- preloadData?: boolean | undefined;
12
+ export declare const usePreloadRoute: () => (url: string | URL, options?: {
13
+ preloadData?: boolean;
14
14
  }) => void;
15
15
  export declare const useMatch: <S extends string>(path: () => S, matchFilters?: MatchFilters<S> | undefined) => Accessor<import("./types.js").PathMatch | undefined>;
16
16
  export declare const useCurrentMatches: () => () => RouteMatch[];
package/dist/routing.js CHANGED
@@ -23,7 +23,10 @@ export const useHref = (to) => {
23
23
  export const useNavigate = () => useRouter().navigatorFactory();
24
24
  export const useLocation = () => useRouter().location;
25
25
  export const useIsRouting = () => useRouter().isRouting;
26
- export const usePreloadRoute = () => useRouter().preloadRoute;
26
+ export const usePreloadRoute = () => {
27
+ const pre = useRouter().preloadRoute;
28
+ return (url, options = {}) => pre(url instanceof URL ? url : new URL(url, mockBase), options.preloadData);
29
+ };
27
30
  export const useMatch = (path, matchFilters) => {
28
31
  const location = useLocation();
29
32
  const matchers = createMemo(() => expandOptionals(path()).map(path => createMatcher(path, undefined, matchFilters)));
@@ -348,7 +351,7 @@ export function createRouterContext(integration, branches, getContext, options =
348
351
  referrers.length = 0;
349
352
  }
350
353
  }
351
- function preloadRoute(url, options = {}) {
354
+ function preloadRoute(url, preloadData) {
352
355
  const matches = getRouteMatches(branches(), url.pathname);
353
356
  const prevIntent = intent;
354
357
  intent = "preload";
@@ -359,7 +362,7 @@ export function createRouterContext(integration, branches, getContext, options =
359
362
  route.component.preload();
360
363
  const { preload } = route;
361
364
  inPreloadFn = true;
362
- options.preloadData &&
365
+ preloadData &&
363
366
  preload &&
364
367
  runWithOwner(getContext(), () => preload({
365
368
  params,
package/dist/types.d.ts CHANGED
@@ -139,9 +139,7 @@ export interface RouterContext {
139
139
  renderPath(path: string): string;
140
140
  parsePath(str: string): string;
141
141
  beforeLeave: BeforeLeaveLifecycle;
142
- preloadRoute: (url: URL, options: {
143
- preloadData?: boolean;
144
- }) => void;
142
+ preloadRoute: (url: URL, preloadData?: boolean) => void;
145
143
  singleFlight: boolean;
146
144
  submissions: Signal<Submission<any, any>[]>;
147
145
  }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "Ryan Turnquist"
7
7
  ],
8
8
  "license": "MIT",
9
- "version": "0.14.8",
9
+ "version": "0.14.9",
10
10
  "homepage": "https://github.com/solidjs/solid-router#readme",
11
11
  "repository": {
12
12
  "type": "git",