@nifrajs/web-solid 5.0.0 → 5.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAUjD,6EAA6E;AAC7E,eAAO,MAAM,YAAY,EAAE,aA2B1B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAgDjD,6EAA6E;AAC7E,eAAO,MAAM,YAAY,EAAE,aA8B1B,CAAA"}
package/dist/index.js CHANGED
@@ -1,6 +1,39 @@
1
+ import { sharedConfig } from "solid-js";
1
2
  import { generateHydrationScript, renderToStream as solidRenderToStream, renderToString as solidRenderToString, } from "solid-js/web";
2
3
  import { compose } from "./compose.js";
3
4
  const HYDRATION_HEAD = generateHydrationScript();
5
+ // An unset NODE_ENV counts as production, as for the framework's own error pages.
6
+ const showsErrors = () => {
7
+ const nodeEnv = typeof process === "undefined" ? undefined : process.env?.NODE_ENV;
8
+ return nodeEnv === "development" || nodeEnv === "test";
9
+ };
10
+ /** What the browser receives for an error Solid hands to hydration: its text names server internals. */
11
+ function redactedError() {
12
+ // Built bare: a constructed Error carries a stack and, on Bun, the line, column and file it was made
13
+ // at, and Solid serializes every own property.
14
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Object.create over Error.prototype with a message is an Error minus its stack.
15
+ return Object.create(Error.prototype, {
16
+ message: { value: "Internal Server Error", writable: true, configurable: true },
17
+ });
18
+ }
19
+ /**
20
+ * Render `app` with every Error that Solid serializes for hydration replaced. An `<ErrorBoundary>` that
21
+ * caught on the server, or a failed resource, otherwise ships the message and stack in an inline script.
22
+ * Nested contexts copy this one, so they keep the wrapped `serialize`.
23
+ */
24
+ function redactingErrors(app) {
25
+ if (showsErrors())
26
+ return app;
27
+ return () => {
28
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Solid's server renderers set a context with serialize; the check below handles its absence.
29
+ const context = sharedConfig.context;
30
+ const serialize = context?.serialize;
31
+ if (context !== undefined && serialize !== undefined) {
32
+ context.serialize = (id, value) => serialize(id, value instanceof Error ? redactedError() : value);
33
+ }
34
+ return app();
35
+ };
36
+ }
4
37
  /** The Solid server render adapter - pass to @nifrajs/web's `renderPage`. */
5
38
  export const solidAdapter = {
6
39
  // Synchronous one-pass render for non-deferred pages (renderPage's buffered fast path). Solid's
@@ -8,8 +41,11 @@ export const solidAdapter = {
8
41
  // `generateHydrationScript()`) as `renderToStream`, but skips the TransformStream + Solid's
9
42
  // streaming machinery - the heaviest of the five renderers on Bun. A page that defer()s/Suspends
10
43
  // takes `renderToStream` below (progressive resolution needs it).
11
- renderToString(chain, props) {
12
- return solidRenderToString(compose(chain, props));
44
+ renderToString(chain, props, options) {
45
+ const app = redactingErrors(compose(chain, props));
46
+ return options?.nonce === undefined
47
+ ? solidRenderToString(app)
48
+ : solidRenderToString(app, { nonce: options.nonce });
13
49
  },
14
50
  renderToStream(chain, props, options) {
15
51
  // Solid's `renderToStream` streams `Uint8Array` chunks into a Web `WritableStream` via
@@ -18,7 +54,7 @@ export const solidAdapter = {
18
54
  // <head>) seeds client hydration. A render failure errors `ts.readable`, which `renderPage`
19
55
  // surfaces on the response body. The nonce reaches the resource and boundary scripts Solid streams.
20
56
  const ts = new TransformStream();
21
- const app = compose(chain, props);
57
+ const app = redactingErrors(compose(chain, props));
22
58
  const stream = options?.nonce === undefined
23
59
  ? solidRenderToStream(app)
24
60
  : solidRenderToStream(app, { nonce: options.nonce });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,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,GAAkB;IACzC,gGAAgG;IAChG,mFAAmF;IACnF,4FAA4F;IAC5F,iGAAiG;IACjG,kEAAkE;IAClE,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO;QAClC,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;QAClD,OAAO,OAAO,EAAE,KAAK,KAAK,SAAS;YACjC,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC;YAC1B,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO;QAClC,uFAAuF;QACvF,2FAA2F;QAC3F,6FAA6F;QAC7F,4FAA4F;QAC5F,oGAAoG;QACpG,MAAM,EAAE,GAAG,IAAI,eAAe,EAA0B,CAAA;QACxD,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;QAClD,MAAM,MAAM,GACV,OAAO,EAAE,KAAK,KAAK,SAAS;YAC1B,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC;YAC1B,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QACxD,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;QAC1B,OAAO,EAAE,CAAC,QAAQ,CAAA;IACpB,CAAC;IACD,aAAa;QACX,OAAO,cAAc,CAAA;IACvB,CAAC;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nifrajs/web-solid",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Solid render adapter for @nifrajs/web - SSR + hydration, with the Solid Babel build plugin (@nifrajs/web-solid/plugin).",
5
5
  "keywords": [
6
6
  "bun",
@@ -121,10 +121,10 @@
121
121
  "dependencies": {
122
122
  "@babel/core": "^7.26.0",
123
123
  "@babel/preset-typescript": "^7.26.0",
124
- "@nifrajs/core": "5.0.0",
125
- "@nifrajs/i18n": "5.0.0",
126
- "@nifrajs/image": "5.0.0",
127
- "@nifrajs/web": "5.0.0",
124
+ "@nifrajs/core": "5.1.0",
125
+ "@nifrajs/i18n": "5.1.0",
126
+ "@nifrajs/image": "5.1.0",
127
+ "@nifrajs/web": "5.1.0",
128
128
  "babel-preset-solid": "^1.9.3",
129
129
  "solid-refresh": "^0.7.8"
130
130
  },
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * Bun-plugin in `@nifrajs/web-solid/plugin`.
6
6
  */
7
7
  import type { RenderAdapter } from "@nifrajs/web"
8
+ import { sharedConfig } from "solid-js"
8
9
  import {
9
10
  generateHydrationScript,
10
11
  renderToStream as solidRenderToStream,
@@ -14,6 +15,43 @@ import { compose } from "./compose.ts"
14
15
 
15
16
  const HYDRATION_HEAD = generateHydrationScript()
16
17
 
18
+ // An unset NODE_ENV counts as production, as for the framework's own error pages.
19
+ const showsErrors = (): boolean => {
20
+ const nodeEnv = typeof process === "undefined" ? undefined : process.env?.NODE_ENV
21
+ return nodeEnv === "development" || nodeEnv === "test"
22
+ }
23
+
24
+ /** What the browser receives for an error Solid hands to hydration: its text names server internals. */
25
+ function redactedError(): Error {
26
+ // Built bare: a constructed Error carries a stack and, on Bun, the line, column and file it was made
27
+ // at, and Solid serializes every own property.
28
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Object.create over Error.prototype with a message is an Error minus its stack.
29
+ return Object.create(Error.prototype, {
30
+ message: { value: "Internal Server Error", writable: true, configurable: true },
31
+ }) as Error
32
+ }
33
+
34
+ /**
35
+ * Render `app` with every Error that Solid serializes for hydration replaced. An `<ErrorBoundary>` that
36
+ * caught on the server, or a failed resource, otherwise ships the message and stack in an inline script.
37
+ * Nested contexts copy this one, so they keep the wrapped `serialize`.
38
+ */
39
+ function redactingErrors<T>(app: () => T): () => T {
40
+ if (showsErrors()) return app
41
+ return () => {
42
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Solid's server renderers set a context with serialize; the check below handles its absence.
43
+ const context = sharedConfig.context as
44
+ | { serialize?: (id: string, value: unknown) => void }
45
+ | undefined
46
+ const serialize = context?.serialize
47
+ if (context !== undefined && serialize !== undefined) {
48
+ context.serialize = (id, value) =>
49
+ serialize(id, value instanceof Error ? redactedError() : value)
50
+ }
51
+ return app()
52
+ }
53
+ }
54
+
17
55
  /** The Solid server render adapter - pass to @nifrajs/web's `renderPage`. */
18
56
  export const solidAdapter: RenderAdapter = {
19
57
  // Synchronous one-pass render for non-deferred pages (renderPage's buffered fast path). Solid's
@@ -21,8 +59,11 @@ export const solidAdapter: RenderAdapter = {
21
59
  // `generateHydrationScript()`) as `renderToStream`, but skips the TransformStream + Solid's
22
60
  // streaming machinery - the heaviest of the five renderers on Bun. A page that defer()s/Suspends
23
61
  // takes `renderToStream` below (progressive resolution needs it).
24
- renderToString(chain, props) {
25
- return solidRenderToString(compose(chain, props))
62
+ renderToString(chain, props, options) {
63
+ const app = redactingErrors(compose(chain, props))
64
+ return options?.nonce === undefined
65
+ ? solidRenderToString(app)
66
+ : solidRenderToString(app, { nonce: options.nonce })
26
67
  },
27
68
  renderToStream(chain, props, options) {
28
69
  // Solid's `renderToStream` streams `Uint8Array` chunks into a Web `WritableStream` via
@@ -31,7 +72,7 @@ export const solidAdapter: RenderAdapter = {
31
72
  // <head>) seeds client hydration. A render failure errors `ts.readable`, which `renderPage`
32
73
  // surfaces on the response body. The nonce reaches the resource and boundary scripts Solid streams.
33
74
  const ts = new TransformStream<Uint8Array, Uint8Array>()
34
- const app = compose(chain, props)
75
+ const app = redactingErrors(compose(chain, props))
35
76
  const stream =
36
77
  options?.nonce === undefined
37
78
  ? solidRenderToStream(app)