@react-email/render 1.0.1 → 1.0.2

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.
@@ -72,6 +72,7 @@ module.exports = __toCommonJS(browser_exports);
72
72
 
73
73
  // src/browser/render.tsx
74
74
  var import_html_to_text = require("html-to-text");
75
+ var import_react = require("react");
75
76
 
76
77
  // src/shared/utils/pretty.ts
77
78
  var import_js_beautify = __toESM(require("js-beautify"));
@@ -97,15 +98,14 @@ var plainTextSelectors = [
97
98
  ];
98
99
 
99
100
  // src/browser/render.tsx
100
- var import_react = require("react");
101
101
  var import_jsx_runtime = require("react/jsx-runtime");
102
102
  var decoder = new TextDecoder("utf-8");
103
103
  var readStream = (stream) => __async(void 0, null, function* () {
104
- let result = "";
104
+ const chunks = [];
105
105
  if ("pipeTo" in stream) {
106
106
  const writableStream = new WritableStream({
107
107
  write(chunk) {
108
- result += decoder.decode(chunk);
108
+ chunks.push(chunk);
109
109
  }
110
110
  });
111
111
  yield stream.pipeTo(writableStream);
@@ -119,7 +119,17 @@ var readStream = (stream) => __async(void 0, null, function* () {
119
119
  }
120
120
  );
121
121
  }
122
- return result;
122
+ let length = 0;
123
+ chunks.forEach((item) => {
124
+ length += item.length;
125
+ });
126
+ const mergedChunks = new Uint8Array(length);
127
+ let offset = 0;
128
+ chunks.forEach((item) => {
129
+ mergedChunks.set(item, offset);
130
+ offset += item.length;
131
+ });
132
+ return decoder.decode(mergedChunks);
123
133
  });
124
134
  var render = (element, options) => __async(void 0, null, function* () {
125
135
  const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: element });
@@ -160,14 +170,15 @@ var render = (element, options) => __async(void 0, null, function* () {
160
170
  // src/browser/render-async.tsx
161
171
  var import_html_to_text2 = require("html-to-text");
162
172
  var import_react2 = require("react");
163
- var import_jsx_runtime2 = require("react/jsx-runtime");
173
+
174
+ // src/browser/read-stream.ts
164
175
  var decoder2 = new TextDecoder("utf-8");
165
176
  var readStream2 = (stream) => __async(void 0, null, function* () {
166
- let result = "";
177
+ const chunks = [];
167
178
  if ("pipeTo" in stream) {
168
179
  const writableStream = new WritableStream({
169
180
  write(chunk) {
170
- result += decoder2.decode(chunk);
181
+ chunks.push(chunk);
171
182
  }
172
183
  });
173
184
  yield stream.pipeTo(writableStream);
@@ -181,8 +192,21 @@ var readStream2 = (stream) => __async(void 0, null, function* () {
181
192
  }
182
193
  );
183
194
  }
184
- return result;
195
+ let length = 0;
196
+ chunks.forEach((item) => {
197
+ length += item.length;
198
+ });
199
+ const mergedChunks = new Uint8Array(length);
200
+ let offset = 0;
201
+ chunks.forEach((item) => {
202
+ mergedChunks.set(item, offset);
203
+ offset += item.length;
204
+ });
205
+ return decoder2.decode(mergedChunks);
185
206
  });
207
+
208
+ // src/browser/render-async.tsx
209
+ var import_jsx_runtime2 = require("react/jsx-runtime");
186
210
  var renderAsync = (element, options) => __async(void 0, null, function* () {
187
211
  const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.Suspense, { children: element });
188
212
  const { default: reactDOMServer } = yield import("react-dom/server");
@@ -37,6 +37,7 @@ var __async = (__this, __arguments, generator) => {
37
37
 
38
38
  // src/browser/render.tsx
39
39
  import { convert } from "html-to-text";
40
+ import { Suspense } from "react";
40
41
 
41
42
  // src/shared/utils/pretty.ts
42
43
  import jsBeautify from "js-beautify";
@@ -62,15 +63,14 @@ var plainTextSelectors = [
62
63
  ];
63
64
 
64
65
  // src/browser/render.tsx
65
- import { Suspense } from "react";
66
66
  import { jsx } from "react/jsx-runtime";
67
67
  var decoder = new TextDecoder("utf-8");
68
68
  var readStream = (stream) => __async(void 0, null, function* () {
69
- let result = "";
69
+ const chunks = [];
70
70
  if ("pipeTo" in stream) {
71
71
  const writableStream = new WritableStream({
72
72
  write(chunk) {
73
- result += decoder.decode(chunk);
73
+ chunks.push(chunk);
74
74
  }
75
75
  });
76
76
  yield stream.pipeTo(writableStream);
@@ -84,7 +84,17 @@ var readStream = (stream) => __async(void 0, null, function* () {
84
84
  }
85
85
  );
86
86
  }
87
- return result;
87
+ let length = 0;
88
+ chunks.forEach((item) => {
89
+ length += item.length;
90
+ });
91
+ const mergedChunks = new Uint8Array(length);
92
+ let offset = 0;
93
+ chunks.forEach((item) => {
94
+ mergedChunks.set(item, offset);
95
+ offset += item.length;
96
+ });
97
+ return decoder.decode(mergedChunks);
88
98
  });
89
99
  var render = (element, options) => __async(void 0, null, function* () {
90
100
  const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: element });
@@ -125,14 +135,15 @@ var render = (element, options) => __async(void 0, null, function* () {
125
135
  // src/browser/render-async.tsx
126
136
  import { convert as convert2 } from "html-to-text";
127
137
  import { Suspense as Suspense2 } from "react";
128
- import { jsx as jsx2 } from "react/jsx-runtime";
138
+
139
+ // src/browser/read-stream.ts
129
140
  var decoder2 = new TextDecoder("utf-8");
130
141
  var readStream2 = (stream) => __async(void 0, null, function* () {
131
- let result = "";
142
+ const chunks = [];
132
143
  if ("pipeTo" in stream) {
133
144
  const writableStream = new WritableStream({
134
145
  write(chunk) {
135
- result += decoder2.decode(chunk);
146
+ chunks.push(chunk);
136
147
  }
137
148
  });
138
149
  yield stream.pipeTo(writableStream);
@@ -146,8 +157,21 @@ var readStream2 = (stream) => __async(void 0, null, function* () {
146
157
  }
147
158
  );
148
159
  }
149
- return result;
160
+ let length = 0;
161
+ chunks.forEach((item) => {
162
+ length += item.length;
163
+ });
164
+ const mergedChunks = new Uint8Array(length);
165
+ let offset = 0;
166
+ chunks.forEach((item) => {
167
+ mergedChunks.set(item, offset);
168
+ offset += item.length;
169
+ });
170
+ return decoder2.decode(mergedChunks);
150
171
  });
172
+
173
+ // src/browser/render-async.tsx
174
+ import { jsx as jsx2 } from "react/jsx-runtime";
151
175
  var renderAsync = (element, options) => __async(void 0, null, function* () {
152
176
  const suspendedElement = /* @__PURE__ */ jsx2(Suspense2, { children: element });
153
177
  const { default: reactDOMServer } = yield import("react-dom/server");
@@ -71,8 +71,8 @@ __export(node_exports, {
71
71
  module.exports = __toCommonJS(node_exports);
72
72
 
73
73
  // src/node/render.tsx
74
- var import_node_stream = require("stream");
75
74
  var import_html_to_text = require("html-to-text");
75
+ var import_react = require("react");
76
76
 
77
77
  // src/shared/utils/pretty.ts
78
78
  var import_js_beautify = __toESM(require("js-beautify"));
@@ -97,9 +97,8 @@ var plainTextSelectors = [
97
97
  }
98
98
  ];
99
99
 
100
- // src/node/render.tsx
101
- var import_react = require("react");
102
- var import_jsx_runtime = require("react/jsx-runtime");
100
+ // src/node/read-stream.ts
101
+ var import_node_stream = require("stream");
103
102
  var decoder = new TextDecoder("utf-8");
104
103
  var readStream = (stream) => __async(void 0, null, function* () {
105
104
  let result = "";
@@ -127,6 +126,9 @@ var readStream = (stream) => __async(void 0, null, function* () {
127
126
  }
128
127
  return result;
129
128
  });
129
+
130
+ // src/node/render.tsx
131
+ var import_jsx_runtime = require("react/jsx-runtime");
130
132
  var render = (element, options) => __async(void 0, null, function* () {
131
133
  const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: element });
132
134
  const { default: reactDOMServer } = yield import("react-dom/server");
@@ -164,43 +166,15 @@ var render = (element, options) => __async(void 0, null, function* () {
164
166
  });
165
167
 
166
168
  // src/node/render-async.tsx
167
- var import_node_stream2 = require("stream");
168
169
  var import_html_to_text2 = require("html-to-text");
169
170
  var import_react2 = require("react");
170
171
  var import_jsx_runtime2 = require("react/jsx-runtime");
171
- var decoder2 = new TextDecoder("utf-8");
172
- var readStream2 = (stream) => __async(void 0, null, function* () {
173
- let result = "";
174
- if ("pipeTo" in stream) {
175
- const writableStream = new WritableStream({
176
- write(chunk) {
177
- result += decoder2.decode(chunk);
178
- }
179
- });
180
- yield stream.pipeTo(writableStream);
181
- } else {
182
- const writable = new import_node_stream2.Writable({
183
- write(chunk, _encoding, callback) {
184
- result += decoder2.decode(chunk);
185
- callback();
186
- }
187
- });
188
- stream.pipe(writable);
189
- return new Promise((resolve, reject) => {
190
- writable.on("error", reject);
191
- writable.on("close", () => {
192
- resolve(result);
193
- });
194
- });
195
- }
196
- return result;
197
- });
198
172
  var renderAsync = (element, options) => __async(void 0, null, function* () {
199
173
  const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.Suspense, { children: element });
200
174
  const { default: reactDOMServer } = yield import("react-dom/server");
201
175
  let html;
202
176
  if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
203
- html = yield readStream2(
177
+ html = yield readStream(
204
178
  yield reactDOMServer.renderToReadableStream(suspendedElement)
205
179
  );
206
180
  } else {
@@ -208,7 +182,7 @@ var renderAsync = (element, options) => __async(void 0, null, function* () {
208
182
  const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
209
183
  onAllReady() {
210
184
  return __async(this, null, function* () {
211
- html = yield readStream2(stream);
185
+ html = yield readStream(stream);
212
186
  resolve();
213
187
  });
214
188
  },
@@ -36,8 +36,8 @@ var __async = (__this, __arguments, generator) => {
36
36
  };
37
37
 
38
38
  // src/node/render.tsx
39
- import { Writable } from "node:stream";
40
39
  import { convert } from "html-to-text";
40
+ import { Suspense } from "react";
41
41
 
42
42
  // src/shared/utils/pretty.ts
43
43
  import jsBeautify from "js-beautify";
@@ -62,9 +62,8 @@ var plainTextSelectors = [
62
62
  }
63
63
  ];
64
64
 
65
- // src/node/render.tsx
66
- import { Suspense } from "react";
67
- import { jsx } from "react/jsx-runtime";
65
+ // src/node/read-stream.ts
66
+ import { Writable } from "node:stream";
68
67
  var decoder = new TextDecoder("utf-8");
69
68
  var readStream = (stream) => __async(void 0, null, function* () {
70
69
  let result = "";
@@ -92,6 +91,9 @@ var readStream = (stream) => __async(void 0, null, function* () {
92
91
  }
93
92
  return result;
94
93
  });
94
+
95
+ // src/node/render.tsx
96
+ import { jsx } from "react/jsx-runtime";
95
97
  var render = (element, options) => __async(void 0, null, function* () {
96
98
  const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: element });
97
99
  const { default: reactDOMServer } = yield import("react-dom/server");
@@ -129,43 +131,15 @@ var render = (element, options) => __async(void 0, null, function* () {
129
131
  });
130
132
 
131
133
  // src/node/render-async.tsx
132
- import { Writable as Writable2 } from "node:stream";
133
134
  import { convert as convert2 } from "html-to-text";
134
135
  import { Suspense as Suspense2 } from "react";
135
136
  import { jsx as jsx2 } from "react/jsx-runtime";
136
- var decoder2 = new TextDecoder("utf-8");
137
- var readStream2 = (stream) => __async(void 0, null, function* () {
138
- let result = "";
139
- if ("pipeTo" in stream) {
140
- const writableStream = new WritableStream({
141
- write(chunk) {
142
- result += decoder2.decode(chunk);
143
- }
144
- });
145
- yield stream.pipeTo(writableStream);
146
- } else {
147
- const writable = new Writable2({
148
- write(chunk, _encoding, callback) {
149
- result += decoder2.decode(chunk);
150
- callback();
151
- }
152
- });
153
- stream.pipe(writable);
154
- return new Promise((resolve, reject) => {
155
- writable.on("error", reject);
156
- writable.on("close", () => {
157
- resolve(result);
158
- });
159
- });
160
- }
161
- return result;
162
- });
163
137
  var renderAsync = (element, options) => __async(void 0, null, function* () {
164
138
  const suspendedElement = /* @__PURE__ */ jsx2(Suspense2, { children: element });
165
139
  const { default: reactDOMServer } = yield import("react-dom/server");
166
140
  let html;
167
141
  if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
168
- html = yield readStream2(
142
+ html = yield readStream(
169
143
  yield reactDOMServer.renderToReadableStream(suspendedElement)
170
144
  );
171
145
  } else {
@@ -173,7 +147,7 @@ var renderAsync = (element, options) => __async(void 0, null, function* () {
173
147
  const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
174
148
  onAllReady() {
175
149
  return __async(this, null, function* () {
176
- html = yield readStream2(stream);
150
+ html = yield readStream(stream);
177
151
  resolve();
178
152
  });
179
153
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-email/render",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Transform React components into HTML email templates",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/browser/index.js",
@@ -86,6 +86,8 @@
86
86
  "react-dom": "^18.0 || ^19.0 || ^19.0.0-rc"
87
87
  },
88
88
  "devDependencies": {
89
+ "@types/react": "npm:types-react@19.0.0-rc.1",
90
+ "@types/react-dom": "npm:types-react-dom@19.0.0-rc.1",
89
91
  "@edge-runtime/vm": "3.1.8",
90
92
  "@types/html-to-text": "9.0.4",
91
93
  "@types/js-beautify": "1.14.3",
package/readme.md CHANGED
@@ -35,7 +35,7 @@ Convert React components into a HTML string.
35
35
  import { MyTemplate } from "../components/MyTemplate";
36
36
  import { render } from "@react-email/render";
37
37
 
38
- const html = render(<MyTemplate firstName="Jim" />);
38
+ const html = await render(<MyTemplate firstName="Jim" />);
39
39
  ```
40
40
 
41
41
  ## License