@taujs/react 0.0.1 → 0.0.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
@@ -1,10 +1,10 @@
1
- # @taujs/server
1
+ # @taujs/react
2
2
 
3
- `npm install @taujs/server`
3
+ `npm install @taujs/react`
4
4
 
5
- `yarn add @taujs/server`
5
+ `yarn add @taujs/react`
6
6
 
7
- `pnpm add @taujs/server`
7
+ `pnpm add @taujs/react`
8
8
 
9
9
  ## CSR; SSR; Streaming SSR; Hydration; Fastify + React 19
10
10
 
package/dist/index.d.ts CHANGED
@@ -29,19 +29,19 @@ type RendererOptions = {
29
29
  };
30
30
  type RenderCallbacks = {
31
31
  onHead: (headContent: string) => void;
32
- onFinish: (initialDataResolved: unknown) => void;
32
+ onFinish: (initialDataPromise: unknown) => void;
33
33
  onError: (error: unknown) => void;
34
34
  };
35
35
  declare const resolveHeadContent: (headContent: string | ((meta: Record<string, unknown>) => string), meta?: Record<string, unknown>) => string;
36
36
  declare const createRenderer: ({ appComponent, headContent }: RendererOptions) => {
37
- renderSSR: (initialDataResolved: Record<string, unknown>, location: string, meta?: Record<string, unknown>) => Promise<{
37
+ renderSSR: (initialDataPromise: Record<string, unknown>, location: string, meta?: Record<string, unknown>) => Promise<{
38
38
  headContent: string;
39
39
  appHtml: string;
40
40
  }>;
41
- renderStream: (serverResponse: ServerResponse, callbacks: RenderCallbacks, initialDataResolved: Record<string, unknown>, location: string, bootstrapModules?: string, meta?: Record<string, unknown>) => void;
41
+ renderStream: (serverResponse: ServerResponse, callbacks: RenderCallbacks, initialDataPromise: Record<string, unknown>, location: string, bootstrapModules?: string, meta?: Record<string, unknown>) => void;
42
42
  };
43
- declare const createRenderStream: (serverResponse: ServerResponse, { onHead, onFinish, onError }: RenderCallbacks, { appComponent, headContent, initialDataResolved, location, bootstrapModules, }: RendererOptions & {
44
- initialDataResolved: Record<string, unknown>;
43
+ declare const createRenderStream: (serverResponse: ServerResponse, { onHead, onFinish, onError }: RenderCallbacks, { appComponent, headContent, initialDataPromise, location, bootstrapModules, }: RendererOptions & {
44
+ initialDataPromise: Record<string, unknown>;
45
45
  location: string;
46
46
  bootstrapModules?: string;
47
47
  }) => void;
package/dist/index.js CHANGED
@@ -117,21 +117,21 @@ import { renderToPipeableStream, renderToString } from "react-dom/server";
117
117
  import { jsx as jsx3 } from "react/jsx-runtime";
118
118
  var resolveHeadContent = (headContent, meta = {}) => typeof headContent === "function" ? headContent(meta) : headContent;
119
119
  var createRenderer = ({ appComponent, headContent }) => {
120
- const renderSSR = async (initialDataResolved, location, meta = {}) => {
121
- const dataForHeadContent = Object.keys(initialDataResolved).length > 0 ? initialDataResolved : meta;
120
+ const renderSSR = async (initialDataPromise, location, meta = {}) => {
121
+ const dataForHeadContent = Object.keys(initialDataPromise).length > 0 ? initialDataPromise : meta;
122
122
  const dynamicHeadContent = resolveHeadContent(headContent, dataForHeadContent);
123
- const appHtml = renderToString(/* @__PURE__ */ jsx3(SSRStoreProvider, { store: createSSRStore(initialDataResolved), children: appComponent({ location }) }));
123
+ const appHtml = renderToString(/* @__PURE__ */ jsx3(SSRStoreProvider, { store: createSSRStore(initialDataPromise), children: appComponent({ location }) }));
124
124
  return {
125
125
  headContent: dynamicHeadContent,
126
126
  appHtml
127
127
  };
128
128
  };
129
- const renderStream = (serverResponse, callbacks, initialDataResolved, location, bootstrapModules, meta = {}) => {
129
+ const renderStream = (serverResponse, callbacks, initialDataPromise, location, bootstrapModules, meta = {}) => {
130
130
  const dynamicHeadContent = resolveHeadContent(headContent, meta);
131
131
  createRenderStream(serverResponse, callbacks, {
132
132
  appComponent: (props) => appComponent({ ...props, location }),
133
133
  headContent: dynamicHeadContent,
134
- initialDataResolved,
134
+ initialDataPromise,
135
135
  location,
136
136
  bootstrapModules
137
137
  });
@@ -141,28 +141,30 @@ var createRenderer = ({ appComponent, headContent }) => {
141
141
  var createRenderStream = (serverResponse, { onHead, onFinish, onError }, {
142
142
  appComponent,
143
143
  headContent,
144
- initialDataResolved,
144
+ initialDataPromise,
145
145
  location,
146
146
  bootstrapModules
147
147
  }) => {
148
- const store = createSSRStore(initialDataResolved);
148
+ const store = createSSRStore(initialDataPromise);
149
149
  const appElement = /* @__PURE__ */ jsx3(SSRStoreProvider, { store, children: appComponent({ location }) });
150
150
  const { pipe } = renderToPipeableStream(appElement, {
151
151
  bootstrapModules: bootstrapModules ? [bootstrapModules] : void 0,
152
152
  onShellReady() {
153
- const dynamicHeadContent = resolveHeadContent(headContent, initialDataResolved);
154
- onHead(dynamicHeadContent);
155
- pipe(
156
- new Writable({
157
- write(chunk, _encoding, callback) {
158
- serverResponse.write(chunk, callback);
159
- },
160
- final(callback) {
161
- onFinish(store.getSnapshot());
162
- callback();
163
- }
164
- })
165
- );
153
+ Promise.resolve(initialDataPromise).then((resolvedData) => {
154
+ const dynamicHeadContent = resolveHeadContent(headContent, resolvedData);
155
+ onHead(dynamicHeadContent);
156
+ pipe(
157
+ new Writable({
158
+ write(chunk, _encoding, callback) {
159
+ serverResponse.write(chunk, callback);
160
+ },
161
+ final(callback) {
162
+ onFinish(store.getSnapshot());
163
+ callback();
164
+ }
165
+ })
166
+ );
167
+ });
166
168
  },
167
169
  onAllReady() {
168
170
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taujs/react",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "taujs | τjs",
5
5
  "author": "Aoede <taujs@aoede.uk.net> (https://www.aoede.uk.net)",
6
6
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "@types/react": "^19.0.2",
44
44
  "@types/react-dom": "^19.0.2",
45
45
  "@vitest/coverage-v8": "^2.1.0",
46
+ "@vitest/ui": "^2.1.9",
46
47
  "jsdom": "^25.0.0",
47
48
  "prettier": "^3.3.3",
48
49
  "react": "^19.0.0",