Skip to content

Commit

Permalink
fix #1917, fix #1918 error handling with serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Oct 18, 2023
1 parent b632dfd commit dd492c5
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .changeset/spotty-rings-try.md
@@ -0,0 +1,6 @@
---
"babel-preset-solid": patch
"solid-js": patch
---

fix #1917, fix #1918 error handling with serialization
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -34,21 +34,21 @@
"@rollup/plugin-replace": "^5.0.2",
"@types/node": "^18.11.19",
"@vitest/coverage-c8": "^0.29.7",
"babel-plugin-jsx-dom-expressions": "^0.37.0",
"babel-plugin-jsx-dom-expressions": "^0.37.2",
"coveralls": "^3.1.1",
"csstype": "^3.1.0",
"dom-expressions": "0.37.1",
"hyper-dom-expressions": "0.37.1",
"dom-expressions": "0.37.3",
"hyper-dom-expressions": "0.37.3",
"jsdom": "^21.1.1",
"lit-dom-expressions": "0.37.1",
"lit-dom-expressions": "0.37.3",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"rollup": "^3.7.5",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-copy": "^3.4.0",
"seroval": "^0.10.4",
"seroval": "^0.11.6",
"simple-git-hooks": "^2.8.1",
"symlink-dir": "^5.0.1",
"tsconfig-replace-paths": "^0.0.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-solid/package.json
Expand Up @@ -14,7 +14,7 @@
"test": "node test.js"
},
"dependencies": {
"babel-plugin-jsx-dom-expressions": "^0.37.0"
"babel-plugin-jsx-dom-expressions": "^0.37.2"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/package.json
Expand Up @@ -227,6 +227,6 @@
],
"dependencies": {
"csstype": "^3.1.0",
"seroval": "^0.10.4"
"seroval": "^0.11.6"
}
}
8 changes: 6 additions & 2 deletions packages/solid/src/reactive/signal.ts
Expand Up @@ -620,8 +620,7 @@ export function createResource<T, S, R>(
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
let v;
if (options.ssrLoadFrom === "initial") initP = options.initialValue as T;
else if (sharedConfig.load && (v = sharedConfig.load(id)))
initP = isPromise(v) && "value" in v ? v.value : v;
else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v;
}
function loadEnd(p: Promise<T> | null, v: T | undefined, error?: any, key?: S) {
if (pr === p) {
Expand Down Expand Up @@ -693,6 +692,11 @@ export function createResource<T, S, R>(
loadEnd(pr, p, undefined, lookup);
return p;
}
if ("value" in p) {
if ((p as any).status === "success") loadEnd(pr, p.value as T, undefined, lookup);
else loadEnd(pr, undefined, undefined, lookup);
return p;
}
pr = p;
scheduled = true;
queueMicrotask(() => (scheduled = false));
Expand Down
11 changes: 8 additions & 3 deletions packages/solid/src/server/rendering.ts
Expand Up @@ -424,8 +424,7 @@ export function createResource<T, S>(
if (p != undefined && typeof p === "object" && "then" in p) {
read.loading = true;
read.state = "pending";
if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
return p
p = p
.then(res => {
read.loading = false;
read.state = "ready";
Expand All @@ -440,7 +439,10 @@ export function createResource<T, S>(
read.error = error = castError(err);
p = null;
notifySuspense(contexts);
throw error;
});
if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
return p;
}
ctx.resources[id].data = p;
if (ctx.serialize) ctx.serialize(id, p);
Expand Down Expand Up @@ -592,7 +594,10 @@ export function Suspense(props: { fallback?: string; children: string }) {
const res = runSuspense();

// never suspended
if (suspenseComplete(value)) return res;
if (suspenseComplete(value)) {
delete ctx.suspense[id];
return res;
}

done = ctx.async ? ctx.registerFragment(id) : undefined;
return catchError(() => {
Expand Down
52 changes: 26 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd492c5

Please sign in to comment.