Skip to content

Commit

Permalink
serialization error handling, experimental async storage
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Oct 24, 2023
1 parent 9821c4f commit 3f3a339
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-knives-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

serialization error handling, experimental async storage
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"babel-plugin-jsx-dom-expressions": "^0.37.2",
"coveralls": "^3.1.1",
"csstype": "^3.1.0",
"dom-expressions": "0.37.3",
"hyper-dom-expressions": "0.37.3",
"dom-expressions": "0.37.6",
"hyper-dom-expressions": "0.37.6",
"jsdom": "^21.1.1",
"lit-dom-expressions": "0.37.3",
"lit-dom-expressions": "0.37.6",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
Expand Down
6 changes: 5 additions & 1 deletion packages/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
"import": "./web/dist/web.js",
"require": "./web/dist/web.cjs"
},
"./web/storage": {
"import": "./web/dist/storage.js",
"require": "./web/dist/storage.cjs"
},
"./web/dist/*": "./web/dist/*",
"./universal": {
"development": {
Expand Down Expand Up @@ -204,7 +208,7 @@
"types:copy": "ncp ../../node_modules/dom-expressions/src/jsx.d.ts ./src/jsx.d.ts && ncp ../../node_modules/dom-expressions/src/jsx-h.d.ts ./h/jsx-runtime/src/jsx.d.ts",
"types:src": "tsc --project ./tsconfig.build.json && ncp ../../node_modules/dom-expressions/src/jsx.d.ts ./types/jsx.d.ts",
"types:web": "tsc --project ./web/tsconfig.build.json",
"types:copy-web": "ncp ../../node_modules/dom-expressions/src/client.d.ts ./web/types/client.d.ts && ncp ../../node_modules/dom-expressions/src/server.d.ts ./web/types/server.d.ts",
"types:copy-web": "ncp ../../node_modules/dom-expressions/src/client.d.ts ./web/types/client.d.ts && ncp ../../node_modules/dom-expressions/src/server.d.ts ./web/types/server.d.ts && ncp ./web/storage/storage.d.ts ./web/types/storage.d.ts",
"types:store": "tsc --project ./store/tsconfig.build.json",
"types:html": "tsc --project ./html/tsconfig.json && ncp ../../node_modules/lit-dom-expressions/types/index.d.ts ./html/types/lit.d.ts",
"types:h": "tsc --project ./h/tsconfig.json && ncp ../../node_modules/hyper-dom-expressions/types/index.d.ts ./h/types/hyperscript.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions packages/solid/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ export default [
external: ["solid-js"],
plugins: [replaceDev(true)].concat(plugins)
},
{
input: "web/storage/storage.ts",
output: [
{
file: "web/dist/storage.cjs",
format: "cjs",
exports: "auto"
},
{
file: "web/dist/storage.js",
format: "es"
}
],
external: ["solid-js/web"],
plugins
},
{
input: "universal/src/index.ts",
output: [
Expand Down
4 changes: 4 additions & 0 deletions packages/solid/web/storage/storage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference types="node" />
import { AsyncLocalStorage } from "node:async_hooks";
import type { RequestEvent } from "../server";
export default function initializeServerStorage<T extends RequestEvent>(): AsyncLocalStorage<T>;
10 changes: 10 additions & 0 deletions packages/solid/web/storage/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AsyncLocalStorage } from "node:async_hooks";
import type { RequestEvent } from "solid-js/web";
import { isServer, RequestContext } from "solid-js/web";

// using global on a symbol for locating it later and detaching for environments that don't support it.
export default function initializeServerStorage<T extends RequestEvent>(): AsyncLocalStorage<T> {
if (!isServer) throw new Error("Attempting to use server context in non-server build");
return ((globalThis as any)[RequestContext] =
(globalThis as any)[RequestContext] || new AsyncLocalStorage<T>());
}
28 changes: 14 additions & 14 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 3f3a339

Please sign in to comment.