@forgebook/react 0.2.1 → 0.2.3

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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  React for [Forgebook](https://www.npmjs.com/package/forgebook): the story types, the renderer the frame mounts a story
4
4
  with, and the adapter that reads a React component's props from its TypeScript types.
5
5
 
6
- **Requirements:** React 18.2 or 19 · `forgebook` · Vite 8 · [MIT licence](https://github.com/ensiria/forgebook/blob/develop/packages/react/LICENSE)
6
+ **Requirements:** React 18.2 or 19 · `forgebook` · Vite 8.3.4+ · [MIT licence](https://github.com/ensiria/forgebook/blob/develop/packages/react/LICENSE)
7
7
 
8
8
  ```sh
9
9
  npm install --save-dev forgebook @forgebook/react
@@ -8,6 +8,20 @@
8
8
  *
9
9
  * @module
10
10
  */
11
- import type { StoryRenderer } from "forgebook/renderer";
11
+ import type { StoryDrawing, StoryRenderer } from "forgebook/renderer";
12
+ /**
13
+ * A story's HTML once everything it waits for came, as a framework's server sends a page: for an adapter whose stories
14
+ * wait for data while they render, which `renderToString` gives up on.
15
+ *
16
+ * @remarks
17
+ * Every render error fails it, one inside a `Suspense` boundary too: a real server would hand that boundary to the
18
+ * browser to try again, which a server test has none of.
19
+ *
20
+ * @param drawing - the story.
21
+ * @param signal - gives up on what still waits.
22
+ * @returns the HTML.
23
+ * @throws the first error of the render.
24
+ */
25
+ export declare const awaitedRenderToString: (drawing: StoryDrawing, signal: AbortSignal) => Promise<string>;
12
26
  /** React as the frame draws with it and the server tests render with it. */
13
27
  export declare const reactRenderer: StoryRenderer;
@@ -12,6 +12,37 @@ import { storyContextOf } from "forgebook/renderer";
12
12
  import { reactFrameRenderer } from "./reactFrameRenderer.js";
13
13
  import { storyElement } from "./storyElement.js";
14
14
  import { inProviders } from "./storyProviders.js";
15
+ /**
16
+ * A story's HTML once everything it waits for came, as a framework's server sends a page: for an adapter whose stories
17
+ * wait for data while they render, which `renderToString` gives up on.
18
+ *
19
+ * @remarks
20
+ * Every render error fails it, one inside a `Suspense` boundary too: a real server would hand that boundary to the
21
+ * browser to try again, which a server test has none of.
22
+ *
23
+ * @param drawing - the story.
24
+ * @param signal - gives up on what still waits.
25
+ * @returns the HTML.
26
+ * @throws the first error of the render.
27
+ */
28
+ export const awaitedRenderToString = async (drawing, signal) => {
29
+ // the entry for a server with web streams: Node's own has them only from React 19.2
30
+ const { renderToReadableStream } = await import("react-dom/server.edge");
31
+ const context = storyContextOf(drawing, drawing.args, () => document.body);
32
+ const errors = [];
33
+ const stream = await renderToReadableStream(inProviders(drawing, storyElement(drawing.story, context, drawing.decorators)),
34
+ // no chunk limit: past it React writes a boundary apart, its fallback and a script in the HTML, however long it waited
35
+ {
36
+ signal,
37
+ progressiveChunkSize: Number.POSITIVE_INFINITY,
38
+ onError: (error) => void errors.push(error)
39
+ });
40
+ // read before everything came, the stream would hold fallbacks too
41
+ await stream.allReady;
42
+ if (errors.length > 0)
43
+ throw errors[0];
44
+ return await new Response(stream).text();
45
+ };
15
46
  /** React as the frame draws with it and the server tests render with it. */
16
47
  export const reactRenderer = {
17
48
  ...reactFrameRenderer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgebook/react",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Forgebook for React: the story types and hooks, the renderer the frame mounts a story with, and the adapter that reads a React component's props.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -60,12 +60,12 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@vitejs/plugin-react": "6.1.2",
63
- "@forgebook/story-format": "0.2.1"
63
+ "@forgebook/story-format": "0.2.3"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "react": "^18.2.0 || ^19.0.0",
67
67
  "react-dom": "^18.2.0 || ^19.0.0",
68
- "forgebook": "^0.3.0"
68
+ "forgebook": "^0.3.2"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/node": "24.19.2",
@@ -76,10 +76,10 @@
76
76
  "react-dom": "19.3.0",
77
77
  "vite": "8.3.5",
78
78
  "vitest": "5.0.5",
79
+ "@forgebook/testing": "0.2.3",
79
80
  "@forgebook/tools": "0.0.0",
80
81
  "@forgebook/typescript-config": "0.0.0",
81
- "forgebook": "0.3.0",
82
- "@forgebook/testing": "0.2.1"
82
+ "forgebook": "0.3.2"
83
83
  },
84
84
  "publishConfig": {
85
85
  "access": "public"