@solidjs/router 0.12.0 → 0.12.1

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.
@@ -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 (cached[1])
91
- ? (cached[1]).then(handleResponse(false), handleResponse(true))
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 (res)
126
- ? (res).then(handleResponse(false), handleResponse(true))
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
@@ -467,6 +467,7 @@ function createRouterContext(integration, getBranches, options = {}) {
467
467
  }
468
468
  });
469
469
  });
470
+ const owner = getOwner();
470
471
  return {
471
472
  base: baseRoute,
472
473
  location,
@@ -577,7 +578,10 @@ function createRouterContext(integration, getBranches, options = {}) {
577
578
  params
578
579
  } = matches[match];
579
580
  route.component && route.component.preload && route.component.preload();
580
- preloadData && route.load && route.load({
581
+ const {
582
+ load
583
+ } = route;
584
+ preloadData && load && runWithOwner(owner, () => load({
581
585
  params,
582
586
  location: {
583
587
  pathname: url.pathname,
@@ -588,7 +592,7 @@ function createRouterContext(integration, getBranches, options = {}) {
588
592
  key: ""
589
593
  },
590
594
  intent: "preload"
591
- });
595
+ }));
592
596
  }
593
597
  intent = prevIntent;
594
598
  }
@@ -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 => {
package/dist/routing.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getOwner, 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";
@@ -236,6 +237,7 @@ export function createRouterContext(integration, getBranches, options = {}) {
236
237
  }
237
238
  });
238
239
  });
240
+ const owner = getOwner();
239
241
  return {
240
242
  base: baseRoute,
241
243
  location,
@@ -331,9 +333,10 @@ export function createRouterContext(integration, getBranches, options = {}) {
331
333
  route.component &&
332
334
  route.component.preload &&
333
335
  route.component.preload();
336
+ const { load } = route;
334
337
  preloadData &&
335
- route.load &&
336
- route.load({
338
+ load &&
339
+ runWithOwner(owner, () => load({
337
340
  params,
338
341
  location: {
339
342
  pathname: url.pathname,
@@ -344,7 +347,7 @@ export function createRouterContext(integration, getBranches, options = {}) {
344
347
  key: ""
345
348
  },
346
349
  intent: "preload"
347
- });
350
+ }));
348
351
  }
349
352
  intent = prevIntent;
350
353
  }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "Ryan Turnquist"
7
7
  ],
8
8
  "license": "MIT",
9
- "version": "0.12.0",
9
+ "version": "0.12.1",
10
10
  "homepage": "https://github.com/solidjs/solid-router#readme",
11
11
  "repository": {
12
12
  "type": "git",