@solidjs/router 0.16.0 → 0.17.0-next.0

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.
Files changed (78) hide show
  1. package/README.md +85 -79
  2. package/dist/components.jsx +22 -16
  3. package/dist/data/action.d.ts +12 -10
  4. package/dist/data/action.js +98 -78
  5. package/dist/data/events.d.ts +8 -1
  6. package/dist/data/events.js +3 -3
  7. package/dist/data/index.d.ts +2 -3
  8. package/dist/data/index.js +2 -3
  9. package/dist/data/query.d.ts +1 -3
  10. package/dist/data/query.js +10 -16
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +212 -261
  13. package/dist/index.jsx +1 -1
  14. package/dist/lifecycle.js +1 -1
  15. package/dist/routers/HashRouter.js +1 -1
  16. package/dist/routers/MemoryRouter.js +1 -1
  17. package/dist/routers/Router.js +2 -2
  18. package/dist/routers/StaticRouter.js +1 -1
  19. package/dist/routers/components.d.ts +0 -4
  20. package/dist/routers/components.jsx +30 -19
  21. package/dist/routing.d.ts +4 -3
  22. package/dist/routing.js +71 -49
  23. package/dist/types.d.ts +3 -18
  24. package/dist/utils.d.ts +1 -0
  25. package/dist/utils.js +8 -0
  26. package/package.json +8 -6
  27. package/dist/data/createAsync.d.ts +0 -32
  28. package/dist/data/createAsync.js +0 -93
  29. package/dist/src/components.d.ts +0 -31
  30. package/dist/src/components.jsx +0 -39
  31. package/dist/src/data/action.d.ts +0 -17
  32. package/dist/src/data/action.js +0 -163
  33. package/dist/src/data/action.spec.d.ts +0 -1
  34. package/dist/src/data/action.spec.js +0 -297
  35. package/dist/src/data/createAsync.d.ts +0 -32
  36. package/dist/src/data/createAsync.js +0 -96
  37. package/dist/src/data/createAsync.spec.d.ts +0 -1
  38. package/dist/src/data/createAsync.spec.js +0 -196
  39. package/dist/src/data/events.d.ts +0 -9
  40. package/dist/src/data/events.js +0 -123
  41. package/dist/src/data/events.spec.d.ts +0 -1
  42. package/dist/src/data/events.spec.js +0 -567
  43. package/dist/src/data/index.d.ts +0 -4
  44. package/dist/src/data/index.js +0 -4
  45. package/dist/src/data/query.d.ts +0 -23
  46. package/dist/src/data/query.js +0 -232
  47. package/dist/src/data/query.spec.d.ts +0 -1
  48. package/dist/src/data/query.spec.js +0 -354
  49. package/dist/src/data/response.d.ts +0 -4
  50. package/dist/src/data/response.js +0 -42
  51. package/dist/src/data/response.spec.d.ts +0 -1
  52. package/dist/src/data/response.spec.js +0 -165
  53. package/dist/src/index.d.ts +0 -7
  54. package/dist/src/index.jsx +0 -6
  55. package/dist/src/lifecycle.d.ts +0 -5
  56. package/dist/src/lifecycle.js +0 -69
  57. package/dist/src/routers/HashRouter.d.ts +0 -9
  58. package/dist/src/routers/HashRouter.js +0 -41
  59. package/dist/src/routers/MemoryRouter.d.ts +0 -24
  60. package/dist/src/routers/MemoryRouter.js +0 -57
  61. package/dist/src/routers/Router.d.ts +0 -9
  62. package/dist/src/routers/Router.js +0 -45
  63. package/dist/src/routers/StaticRouter.d.ts +0 -6
  64. package/dist/src/routers/StaticRouter.js +0 -15
  65. package/dist/src/routers/components.d.ts +0 -27
  66. package/dist/src/routers/components.jsx +0 -118
  67. package/dist/src/routers/createRouter.d.ts +0 -10
  68. package/dist/src/routers/createRouter.js +0 -41
  69. package/dist/src/routers/index.d.ts +0 -11
  70. package/dist/src/routers/index.js +0 -6
  71. package/dist/src/routing.d.ts +0 -175
  72. package/dist/src/routing.js +0 -560
  73. package/dist/src/types.d.ts +0 -200
  74. package/dist/src/types.js +0 -1
  75. package/dist/src/utils.d.ts +0 -13
  76. package/dist/src/utils.js +0 -185
  77. package/dist/test/helpers.d.ts +0 -6
  78. package/dist/test/helpers.js +0 -50
@@ -1,8 +1,8 @@
1
- import { delegateEvents } from "solid-js/web";
1
+ import { delegateEvents } from "@solidjs/web";
2
2
  import { onCleanup } from "solid-js";
3
3
  import { actions } from "./action.js";
4
4
  import { mockBase } from "../utils.js";
5
- export function setupNativeEvents(preload = true, explicitLinks = false, actionBase = "/_server", transformUrl) {
5
+ export function setupNativeEvents({ preload = true, explicitLinks = false, actionBase = "/_server", transformUrl } = {}) {
6
6
  return (router) => {
7
7
  const basePath = router.base.path();
8
8
  const navigateFromRoute = router.navigatorFactory(router.base);
@@ -65,7 +65,7 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
65
65
  clearTimeout(preloadTimeout);
66
66
  const res = handleAnchor(evt);
67
67
  if (!res)
68
- return lastElement = null;
68
+ return (lastElement = null);
69
69
  const [a, url] = res;
70
70
  if (lastElement === a)
71
71
  return;
@@ -1,4 +1,3 @@
1
- export { createAsync, createAsyncStore, type AccessorWithLatest } from "./createAsync.js";
2
- export { action, useSubmission, useSubmissions, useAction, type Action } from "./action.js";
3
- export { query, revalidate, cache, type CachedFunction } from "./query.js";
1
+ export { action, useSubmissions, useAction, type Action } from "./action.js";
2
+ export { query, revalidate, type CachedFunction } from "./query.js";
4
3
  export { redirect, reload, json } from "./response.js";
@@ -1,4 +1,3 @@
1
- export { createAsync, createAsyncStore } from "./createAsync.js";
2
- export { action, useSubmission, useSubmissions, useAction } from "./action.js";
3
- export { query, revalidate, cache } from "./query.js";
1
+ export { action, useSubmissions, useAction } from "./action.js";
2
+ export { query, revalidate } from "./query.js";
4
3
  export { redirect, reload, json } from "./response.js";
@@ -2,7 +2,7 @@ import type { CacheEntry, NarrowResponse } from "../types.js";
2
2
  /**
3
3
  * Revalidates the given cache entry/entries.
4
4
  */
5
- export declare function revalidate(key?: string | string[] | void, force?: boolean): Promise<void>;
5
+ export declare function revalidate(key?: string | string[] | void, force?: boolean): void;
6
6
  export declare function cacheKeyOp(key: string | string[] | void, fn: (cacheEntry: CacheEntry) => void): void;
7
7
  export type CachedFunction<T extends (...args: any) => any> = T extends (...args: infer A) => infer R ? ([] extends {
8
8
  [K in keyof A]-?: A[K];
@@ -18,6 +18,4 @@ export declare namespace query {
18
18
  export var clear: () => void;
19
19
  export { _a as delete };
20
20
  }
21
- /** @deprecated use query instead */
22
- export declare const cache: typeof query;
23
21
  export declare function hashKey<T extends Array<any>>(args: T): string;
@@ -1,5 +1,5 @@
1
- import { createSignal, getListener, getOwner, onCleanup, sharedConfig, startTransition } from "solid-js";
2
- import { getRequestEvent, isServer } from "solid-js/web";
1
+ import { createSignal, getObserver, getOwner, onCleanup, sharedConfig } from "solid-js";
2
+ import { getRequestEvent, isServer } from "@solidjs/web";
3
3
  import { useNavigate, getIntent, getInPreloadFn } from "../routing.js";
4
4
  const LocationHeader = "Location";
5
5
  const PRELOAD_TIMEOUT = 5000;
@@ -28,12 +28,10 @@ function getCache() {
28
28
  * Revalidates the given cache entry/entries.
29
29
  */
30
30
  export function revalidate(key, force = true) {
31
- return startTransition(() => {
32
- const now = Date.now();
33
- cacheKeyOp(key, entry => {
34
- force && (entry[0] = 0); //force cache miss
35
- entry[4][1](now); // retrigger live signals
36
- });
31
+ const now = Date.now();
32
+ cacheKeyOp(key, entry => {
33
+ force && (entry[0] = 0); //force cache miss
34
+ entry[4][1](now); // retrigger live signals
37
35
  });
38
36
  }
39
37
  export function cacheKeyOp(key, fn) {
@@ -72,7 +70,7 @@ export function query(fn, name) {
72
70
  }
73
71
  }
74
72
  }
75
- if (getListener() && !isServer) {
73
+ if (getObserver() && !isServer) {
76
74
  tracking = true;
77
75
  onCleanup(() => cached[4].count--);
78
76
  }
@@ -95,7 +93,7 @@ export function query(fn, name) {
95
93
  "then" in cached[1]
96
94
  ? cached[1].then(handleResponse(false), handleResponse(true))
97
95
  : handleResponse(false)(cached[1]);
98
- !isServer && intent === "navigate" && startTransition(() => cached[4][1](cached[0])); // update version
96
+ !isServer && intent === "navigate" && cached[4][1](cached[0]); // update version
99
97
  }
100
98
  inPreloadFn && "then" in res && res.catch(() => { });
101
99
  return res;
@@ -112,7 +110,7 @@ export function query(fn, name) {
112
110
  cached[0] = now;
113
111
  cached[1] = res;
114
112
  cached[3] = intent;
115
- !isServer && intent === "navigate" && startTransition(() => cached[4][1](cached[0])); // update version
113
+ !isServer && intent === "navigate" && cached[4][1](cached[0]); // update version
116
114
  }
117
115
  else {
118
116
  cache.set(key, (cached = [now, res, , intent, createSignal(now)]));
@@ -159,9 +157,7 @@ export function query(fn, name) {
159
157
  if (url !== null) {
160
158
  // client + server relative redirect
161
159
  if (navigate && url.startsWith("/"))
162
- startTransition(() => {
163
- navigate(url, { replace: true });
164
- });
160
+ navigate(url, { replace: true });
165
161
  else if (!isServer)
166
162
  window.location.href = url;
167
163
  else if (e)
@@ -203,8 +199,6 @@ query.set = (key, value) => {
203
199
  };
204
200
  query.delete = (key) => getCache().delete(key);
205
201
  query.clear = () => getCache().clear();
206
- /** @deprecated use query instead */
207
- export const cache = query;
208
202
  function matchKey(key, keys) {
209
203
  for (let k of keys) {
210
204
  if (k && key.startsWith(k))
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from "./routers/index.js";
2
2
  export * from "./components.jsx";
3
3
  export * from "./lifecycle.js";
4
- export { useHref, useIsRouting, useLocation, useMatch, useCurrentMatches, useNavigate, useParams, useResolvedPath, useSearchParams, useBeforeLeave, usePreloadRoute } from "./routing.js";
4
+ export { useHref, useIsRouting, useLocation, useMatch, useCurrentMatches, useNavigate, useParams, useResolvedPath, useSearchParams, useBeforeLeave, usePreloadRoute, RouterContextObj as RouterContext } from "./routing.js";
5
5
  export { mergeSearchString as _mergeSearchString } from "./utils.js";
6
6
  export * from "./data/index.js";
7
- export type { Location, LocationChange, SearchParams, MatchFilter, MatchFilters, NavigateOptions, Navigator, OutputMatch, Params, PathMatch, RouteSectionProps, RoutePreloadFunc, RoutePreloadFuncArgs, RouteDefinition, RouteDescription, RouteMatch, RouterIntegration, RouterUtils, SetParams, Submission, BeforeLeaveEventArgs, RouteLoadFunc, RouteLoadFuncArgs, RouterResponseInit, CustomResponse } from "./types.js";
7
+ export type { Location, LocationChange, SearchParams, MatchFilter, MatchFilters, NavigateOptions, Navigator, OutputMatch, Params, PathMatch, RouteSectionProps, RoutePreloadFunc, RoutePreloadFuncArgs, RouteDefinition, RouteDescription, RouteMatch, RouterIntegration, RouterUtils, SetParams, Submission, BeforeLeaveEventArgs, RouterResponseInit, CustomResponse } from "./types.js";