@react-email/render 1.1.2-canary.0 → 1.1.3-canary.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.
@@ -23,7 +23,7 @@ declare const plainTextSelectors: SelectorDefinition[];
23
23
 
24
24
  declare const pretty: (str: string, options?: Options$1) => Promise<string>;
25
25
 
26
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
26
+ declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
27
27
 
28
28
  /**
29
29
  * @deprecated use {@link render}
@@ -23,7 +23,7 @@ declare const plainTextSelectors: SelectorDefinition[];
23
23
 
24
24
  declare const pretty: (str: string, options?: Options$1) => Promise<string>;
25
25
 
26
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
26
+ declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
27
27
 
28
28
  /**
29
29
  * @deprecated use {@link render}
@@ -89,7 +89,7 @@ var plainTextSelectors = [
89
89
  ];
90
90
 
91
91
  // src/shared/utils/pretty.ts
92
- var import_html = __toESM(require("prettier/plugins/html"));
92
+ var html = __toESM(require("prettier/plugins/html"));
93
93
  var import_standalone = require("prettier/standalone");
94
94
  function recursivelyMapDoc(doc, callback) {
95
95
  if (Array.isArray(doc)) {
@@ -124,7 +124,7 @@ function recursivelyMapDoc(doc, callback) {
124
124
  }
125
125
  return callback(doc);
126
126
  }
127
- var modifiedHtml = __spreadValues({}, import_html.default);
127
+ var modifiedHtml = __spreadValues({}, html);
128
128
  if (modifiedHtml.printers) {
129
129
  const previousPrint = modifiedHtml.printers.html.print;
130
130
  modifiedHtml.printers.html.print = (path, options, print, args) => {
@@ -158,23 +158,19 @@ var import_jsx_runtime = require("react/jsx-runtime");
158
158
  var decoder = new TextDecoder("utf-8");
159
159
  var readStream = (stream) => __async(void 0, null, function* () {
160
160
  const chunks = [];
161
- if ("pipeTo" in stream) {
162
- const writableStream = new WritableStream({
163
- write(chunk) {
164
- chunks.push(chunk);
165
- }
166
- });
167
- yield stream.pipeTo(writableStream);
168
- } else {
169
- throw new Error(
170
- "For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
171
- {
161
+ const writableStream = new WritableStream({
162
+ write(chunk) {
163
+ chunks.push(chunk);
164
+ },
165
+ abort(reason) {
166
+ throw new Error("Stream aborted", {
172
167
  cause: {
173
- stream
168
+ reason
174
169
  }
175
- }
176
- );
177
- }
170
+ });
171
+ }
172
+ });
173
+ yield stream.pipeTo(writableStream);
178
174
  let length = 0;
179
175
  chunks.forEach((item) => {
180
176
  length += item.length;
@@ -187,32 +183,19 @@ var readStream = (stream) => __async(void 0, null, function* () {
187
183
  });
188
184
  return decoder.decode(mergedChunks);
189
185
  });
190
- var render = (element, options) => __async(void 0, null, function* () {
191
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: element });
192
- const reactDOMServer = yield import("react-dom/server").then(
186
+ var render = (node, options) => __async(void 0, null, function* () {
187
+ const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: node });
188
+ const reactDOMServer = yield import("react-dom/server.browser").then(
193
189
  // This is beacuse react-dom/server is CJS
194
190
  (m) => m.default
195
191
  );
196
- let html2;
197
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
198
- html2 = yield readStream(
199
- yield reactDOMServer.renderToReadableStream(suspendedElement)
200
- );
201
- } else {
202
- yield new Promise((resolve, reject) => {
203
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
204
- onAllReady() {
205
- return __async(this, null, function* () {
206
- html2 = yield readStream(stream);
207
- resolve();
208
- });
209
- },
210
- onError(error) {
211
- reject(error);
212
- }
213
- });
214
- });
215
- }
192
+ const html2 = yield new Promise((resolve, reject) => {
193
+ reactDOMServer.renderToReadableStream(suspendedElement, {
194
+ onError(error) {
195
+ reject(error);
196
+ }
197
+ }).then(readStream).then(resolve).catch(reject);
198
+ });
216
199
  if (options == null ? void 0 : options.plainText) {
217
200
  return (0, import_html_to_text.convert)(html2, __spreadValues({
218
201
  selectors: plainTextSelectors
@@ -53,7 +53,7 @@ var plainTextSelectors = [
53
53
  ];
54
54
 
55
55
  // src/shared/utils/pretty.ts
56
- import html from "prettier/plugins/html";
56
+ import * as html from "prettier/plugins/html";
57
57
  import { format } from "prettier/standalone";
58
58
  function recursivelyMapDoc(doc, callback) {
59
59
  if (Array.isArray(doc)) {
@@ -122,23 +122,19 @@ import { jsx } from "react/jsx-runtime";
122
122
  var decoder = new TextDecoder("utf-8");
123
123
  var readStream = (stream) => __async(void 0, null, function* () {
124
124
  const chunks = [];
125
- if ("pipeTo" in stream) {
126
- const writableStream = new WritableStream({
127
- write(chunk) {
128
- chunks.push(chunk);
129
- }
130
- });
131
- yield stream.pipeTo(writableStream);
132
- } else {
133
- throw new Error(
134
- "For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
135
- {
125
+ const writableStream = new WritableStream({
126
+ write(chunk) {
127
+ chunks.push(chunk);
128
+ },
129
+ abort(reason) {
130
+ throw new Error("Stream aborted", {
136
131
  cause: {
137
- stream
132
+ reason
138
133
  }
139
- }
140
- );
141
- }
134
+ });
135
+ }
136
+ });
137
+ yield stream.pipeTo(writableStream);
142
138
  let length = 0;
143
139
  chunks.forEach((item) => {
144
140
  length += item.length;
@@ -151,32 +147,19 @@ var readStream = (stream) => __async(void 0, null, function* () {
151
147
  });
152
148
  return decoder.decode(mergedChunks);
153
149
  });
154
- var render = (element, options) => __async(void 0, null, function* () {
155
- const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: element });
156
- const reactDOMServer = yield import("react-dom/server").then(
150
+ var render = (node, options) => __async(void 0, null, function* () {
151
+ const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: node });
152
+ const reactDOMServer = yield import("react-dom/server.browser").then(
157
153
  // This is beacuse react-dom/server is CJS
158
154
  (m) => m.default
159
155
  );
160
- let html2;
161
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
162
- html2 = yield readStream(
163
- yield reactDOMServer.renderToReadableStream(suspendedElement)
164
- );
165
- } else {
166
- yield new Promise((resolve, reject) => {
167
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
168
- onAllReady() {
169
- return __async(this, null, function* () {
170
- html2 = yield readStream(stream);
171
- resolve();
172
- });
173
- },
174
- onError(error) {
175
- reject(error);
176
- }
177
- });
178
- });
179
- }
156
+ const html2 = yield new Promise((resolve, reject) => {
157
+ reactDOMServer.renderToReadableStream(suspendedElement, {
158
+ onError(error) {
159
+ reject(error);
160
+ }
161
+ }).then(readStream).then(resolve).catch(reject);
162
+ });
180
163
  if (options == null ? void 0 : options.plainText) {
181
164
  return convert(html2, __spreadValues({
182
165
  selectors: plainTextSelectors
@@ -23,7 +23,7 @@ declare const plainTextSelectors: SelectorDefinition[];
23
23
 
24
24
  declare const pretty: (str: string, options?: Options$1) => Promise<string>;
25
25
 
26
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
26
+ declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
27
27
 
28
28
  /**
29
29
  * @deprecated use {@link render}
@@ -23,7 +23,7 @@ declare const plainTextSelectors: SelectorDefinition[];
23
23
 
24
24
  declare const pretty: (str: string, options?: Options$1) => Promise<string>;
25
25
 
26
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
26
+ declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
27
27
 
28
28
  /**
29
29
  * @deprecated use {@link render}
@@ -89,7 +89,7 @@ var plainTextSelectors = [
89
89
  ];
90
90
 
91
91
  // src/shared/utils/pretty.ts
92
- var import_html = __toESM(require("prettier/plugins/html"));
92
+ var html = __toESM(require("prettier/plugins/html"));
93
93
  var import_standalone = require("prettier/standalone");
94
94
  function recursivelyMapDoc(doc, callback) {
95
95
  if (Array.isArray(doc)) {
@@ -124,7 +124,7 @@ function recursivelyMapDoc(doc, callback) {
124
124
  }
125
125
  return callback(doc);
126
126
  }
127
- var modifiedHtml = __spreadValues({}, import_html.default);
127
+ var modifiedHtml = __spreadValues({}, html);
128
128
  if (modifiedHtml.printers) {
129
129
  const previousPrint = modifiedHtml.printers.html.print;
130
130
  modifiedHtml.printers.html.print = (path, options, print, args) => {
@@ -185,8 +185,8 @@ var readStream = (stream) => __async(void 0, null, function* () {
185
185
 
186
186
  // src/node/render.tsx
187
187
  var import_jsx_runtime = require("react/jsx-runtime");
188
- var render = (element, options) => __async(void 0, null, function* () {
189
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: element });
188
+ var render = (node, options) => __async(void 0, null, function* () {
189
+ const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: node });
190
190
  const reactDOMServer = yield import("react-dom/server").then(
191
191
  // This is beacuse react-dom/server is CJS
192
192
  (m) => m.default
@@ -53,7 +53,7 @@ var plainTextSelectors = [
53
53
  ];
54
54
 
55
55
  // src/shared/utils/pretty.ts
56
- import html from "prettier/plugins/html";
56
+ import * as html from "prettier/plugins/html";
57
57
  import { format } from "prettier/standalone";
58
58
  function recursivelyMapDoc(doc, callback) {
59
59
  if (Array.isArray(doc)) {
@@ -149,8 +149,8 @@ var readStream = (stream) => __async(void 0, null, function* () {
149
149
 
150
150
  // src/node/render.tsx
151
151
  import { jsx } from "react/jsx-runtime";
152
- var render = (element, options) => __async(void 0, null, function* () {
153
- const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: element });
152
+ var render = (node, options) => __async(void 0, null, function* () {
153
+ const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: node });
154
154
  const reactDOMServer = yield import("react-dom/server").then(
155
155
  // This is beacuse react-dom/server is CJS
156
156
  (m) => m.default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-email/render",
3
- "version": "1.1.2-canary.0",
3
+ "version": "1.1.3-canary.0",
4
4
  "description": "Transform React components into HTML email templates",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/browser/index.js",