From 3f3a3396eb9acb9f0482f4e96ac390d158d89b63 Mon Sep 17 00:00:00 2001 From: Ryan Carniato Date: Tue, 24 Oct 2023 16:09:11 -0700 Subject: [PATCH] serialization error handling, experimental async storage --- .changeset/fast-knives-sneeze.md | 5 +++++ package.json | 6 +++--- packages/solid/package.json | 6 +++++- packages/solid/rollup.config.js | 16 ++++++++++++++ packages/solid/web/storage/storage.d.ts | 4 ++++ packages/solid/web/storage/storage.ts | 10 +++++++++ pnpm-lock.yaml | 28 ++++++++++++------------- 7 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 .changeset/fast-knives-sneeze.md create mode 100644 packages/solid/web/storage/storage.d.ts create mode 100644 packages/solid/web/storage/storage.ts diff --git a/.changeset/fast-knives-sneeze.md b/.changeset/fast-knives-sneeze.md new file mode 100644 index 000000000..7f072615d --- /dev/null +++ b/.changeset/fast-knives-sneeze.md @@ -0,0 +1,5 @@ +--- +"solid-js": patch +--- + +serialization error handling, experimental async storage diff --git a/package.json b/package.json index f2a9c0c34..0eefe2cd4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/solid/package.json b/packages/solid/package.json index 7eefb0628..53953239a 100644 --- a/packages/solid/package.json +++ b/packages/solid/package.json @@ -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": { @@ -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", diff --git a/packages/solid/rollup.config.js b/packages/solid/rollup.config.js index 5e9f1da41..c92ea6e85 100644 --- a/packages/solid/rollup.config.js +++ b/packages/solid/rollup.config.js @@ -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: [ diff --git a/packages/solid/web/storage/storage.d.ts b/packages/solid/web/storage/storage.d.ts new file mode 100644 index 000000000..5f996a01f --- /dev/null +++ b/packages/solid/web/storage/storage.d.ts @@ -0,0 +1,4 @@ +/// +import { AsyncLocalStorage } from "node:async_hooks"; +import type { RequestEvent } from "../server"; +export default function initializeServerStorage(): AsyncLocalStorage; diff --git a/packages/solid/web/storage/storage.ts b/packages/solid/web/storage/storage.ts new file mode 100644 index 000000000..54b34b2a1 --- /dev/null +++ b/packages/solid/web/storage/storage.ts @@ -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(): AsyncLocalStorage { + 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()); +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a111741f..c68101c92 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -57,17 +57,17 @@ importers: specifier: ^3.1.0 version: 3.1.0 dom-expressions: - specifier: 0.37.3 - version: 0.37.3(csstype@3.1.0)(seroval@0.11.6) + specifier: 0.37.6 + version: 0.37.6(csstype@3.1.0)(seroval@0.11.6) hyper-dom-expressions: - specifier: 0.37.3 - version: 0.37.3 + specifier: 0.37.6 + version: 0.37.6 jsdom: specifier: ^21.1.1 version: 21.1.1 lit-dom-expressions: - specifier: 0.37.3 - version: 0.37.3 + specifier: 0.37.6 + version: 0.37.6 ncp: specifier: ^2.0.0 version: 2.0.0 @@ -2889,11 +2889,11 @@ packages: path-type: 4.0.0 dev: true - /dom-expressions@0.37.3(csstype@3.1.0)(seroval@0.11.6): - resolution: {integrity: sha512-XUIuHLYdEibGVVXN09fd2krN07xHi1XKvJ/eozJH3TycKsMPjJOOcS9rCkglHvMnrOaw73ODjJEsvhzFnl7Rkw==} + /dom-expressions@0.37.6(csstype@3.1.0)(seroval@0.11.6): + resolution: {integrity: sha512-O9X5kXoHgt/bjCSAIHlwB1DWzXKgPyKFKDTgzJIUVenEXuTsb27h4SW5CagAzE2OidmNJc+TbHRwUmqKBbM6SQ==} peerDependencies: csstype: ^3.0 - seroval: ^0.11.4 + seroval: ^0.12.0 dependencies: babel-plugin-transform-rename-import: 2.3.0 csstype: 3.1.0 @@ -3637,8 +3637,8 @@ packages: resolution: {integrity: sha512-UNopramDEhHJD+VR+ehk8rOslwSfByxPIZyJRfV739NDhN5LF1fa1MqnzKm2lGTQRjNrjK19Q5fhkgIfjlVUKw==} dev: true - /hyper-dom-expressions@0.37.3: - resolution: {integrity: sha512-YXvTiNCcdCAu51gT/h3a2AS5X1PUo4fR1srXiu6y7qWSU4J+f5mL9bjwjit8h/EiBAVG+Vhg8ZX123c5Aid5lg==} + /hyper-dom-expressions@0.37.6: + resolution: {integrity: sha512-hbUzGeHVuCIH942BtzpaQ/qPwPqUsE+xMY0rt54x6RSKPSo53U0R88czAHTfCK++TvZxuGdw7GT9dw9fI9Ng5w==} dev: true /iconv-lite@0.4.24: @@ -4079,8 +4079,8 @@ packages: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} dev: true - /lit-dom-expressions@0.37.3: - resolution: {integrity: sha512-ubFMz5SGFlteSI2Gixr1eE+9feyH1zTePIFDLhqy9QJGmTZEhRY0wIHDDSK3CknE7UdsvHiLKihpJlyqeO9pSw==} + /lit-dom-expressions@0.37.6: + resolution: {integrity: sha512-j5K1L2Zq5QGra+fNqSm7wtIavUpMVgqWHPL2j0lyMhuf+U60sl2wzDu7MsMGC2KJDOPWnm/8hbBTHQfQQTgl8A==} dev: true /load-json-file@4.0.0: