summaryrefslogtreecommitdiff
path: root/packages/integrations/react
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-04-20 17:17:36 -0400
committerGravatar Matthew Phillips <matthew@skypack.dev> 2022-04-20 17:17:36 -0400
commite621c2f7d3844e950168f4198e4dd1c6f43031d0 (patch)
tree6c8cdae67acb0957054f2d1bcad832beb784d356 /packages/integrations/react
parent700d4f9649b72e98a56586a480e6d3c413cf45f1 (diff)
downloadastro-e621c2f7d3844e950168f4198e4dd1c6f43031d0.tar.gz
astro-e621c2f7d3844e950168f4198e4dd1c6f43031d0.tar.zst
astro-e621c2f7d3844e950168f4198e4dd1c6f43031d0.zip
Revert "Fixes using React.lazy and Suspense"
This reverts commit 700d4f9649b72e98a56586a480e6d3c413cf45f1.
Diffstat (limited to 'packages/integrations/react')
-rw-r--r--packages/integrations/react/server.js76
1 files changed, 4 insertions, 72 deletions
diff --git a/packages/integrations/react/server.js b/packages/integrations/react/server.js
index b41492a7a..6ae49e7bc 100644
--- a/packages/integrations/react/server.js
+++ b/packages/integrations/react/server.js
@@ -12,7 +12,7 @@ function errorIsComingFromPreactComponent(err) {
);
}
-async function check(Component, props, children) {
+function check(Component, props, children) {
// Note: there are packages that do some unholy things to create "components".
// Checking the $$typeof property catches most of these patterns.
if (typeof Component === 'object') {
@@ -42,7 +42,7 @@ async function check(Component, props, children) {
return React.createElement('div');
}
- await renderToStaticMarkup(Tester, props, children, {});
+ renderToStaticMarkup(Tester, props, children, {});
if (error) {
throw error;
@@ -50,13 +50,7 @@ async function check(Component, props, children) {
return isReactComponent;
}
-async function getNodeWritable() {
- let nodeStreamBuiltinModuleName = 'stream';
- let { Writable } = await import(nodeStreamBuiltinModuleName);
- return Writable;
-}
-
-async function renderToStaticMarkup(Component, props, children, metadata) {
+function renderToStaticMarkup(Component, props, children, metadata) {
delete props['class'];
const vnode = React.createElement(Component, {
...props,
@@ -65,74 +59,12 @@ async function renderToStaticMarkup(Component, props, children, metadata) {
let html;
if (metadata && metadata.hydrate) {
html = ReactDOM.renderToString(vnode);
- if('renderToReadableStream' in ReactDOM) {
- html = await renderToReadableStreamAsync(vnode);
- } else {
- html = await renderToPipeableStreamAsync(vnode);
- }
} else {
- if('renderToReadableStream' in ReactDOM) {
- html = await renderToReadableStreamAsync(vnode);
- } else {
- html = await renderToStaticNodeStreamAsync(vnode);
- }
-
+ html = ReactDOM.renderToStaticMarkup(vnode);
}
return { html };
}
-async function renderToPipeableStreamAsync(vnode) {
- const Writable = await getNodeWritable();
- let html = '';
- return new Promise((resolve, reject) => {
- let error = undefined;
- let stream = ReactDOM.renderToPipeableStream(vnode, {
- onError(err) {
- error = err;
- reject(error);
- },
- onAllReady() {
- stream.pipe(new Writable({
- write(chunk, _encoding, callback) {
- html += chunk.toString('utf-8');
- callback();
- },
- destroy() {
- resolve(html);
- }
- }));
- }
- });
- });
-}
-
-async function renderToStaticNodeStreamAsync(vnode) {
- const Writable = await getNodeWritable();
- let html = '';
- return new Promise((resolve) => {
- let stream = ReactDOM.renderToStaticNodeStream(vnode);
- stream.pipe(new Writable({
- write(chunk, _encoding, callback) {
- html += chunk.toString('utf-8');
- callback();
- },
- destroy() {
- resolve(html);
- }
- }));
- });
-}
-
-async function renderToReadableStreamAsync(vnode) {
- const decoder = new TextDecoder();
- const stream = await ReactDOM.renderToReadableStream(vnode);
- let html = '';
- for await(const chunk of stream) {
- html += decoder.decode(chunk);
- }
- return html;
-}
-
export default {
check,
renderToStaticMarkup,