mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
fix a deprecated method in react integration using SSR: renderToStaticNodeStream (#10893)
* deprecated method renderToStaticNodeStream * Create twelve-bulldogs-raise.md --------- Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
parent
36bb3b6025
commit
fd7a9ed337
2 changed files with 8 additions and 33 deletions
5
.changeset/twelve-bulldogs-raise.md
Normal file
5
.changeset/twelve-bulldogs-raise.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/react": patch
|
||||
---
|
||||
|
||||
Removes using deprecated `ReactDOMServer.renderToStaticNodeStream` API
|
|
@ -106,18 +106,10 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl
|
|||
identifierPrefix: prefix,
|
||||
};
|
||||
let html;
|
||||
if (metadata?.hydrate) {
|
||||
if ('renderToReadableStream' in ReactDOM) {
|
||||
html = await renderToReadableStreamAsync(vnode, renderOptions);
|
||||
} else {
|
||||
html = await renderToPipeableStreamAsync(vnode, renderOptions);
|
||||
}
|
||||
if ('renderToReadableStream' in ReactDOM) {
|
||||
html = await renderToReadableStreamAsync(vnode, renderOptions);
|
||||
} else {
|
||||
if ('renderToReadableStream' in ReactDOM) {
|
||||
html = await renderToReadableStreamAsync(vnode, renderOptions);
|
||||
} else {
|
||||
html = await renderToStaticNodeStreamAsync(vnode, renderOptions);
|
||||
}
|
||||
html = await renderToPipeableStreamAsync(vnode, renderOptions);
|
||||
}
|
||||
return { html, attrs };
|
||||
}
|
||||
|
@ -150,28 +142,6 @@ async function renderToPipeableStreamAsync(vnode, options) {
|
|||
});
|
||||
}
|
||||
|
||||
async function renderToStaticNodeStreamAsync(vnode, options) {
|
||||
const Writable = await getNodeWritable();
|
||||
let html = '';
|
||||
return new Promise((resolve, reject) => {
|
||||
let stream = ReactDOM.renderToStaticNodeStream(vnode, options);
|
||||
stream.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
stream.pipe(
|
||||
new Writable({
|
||||
write(chunk, _encoding, callback) {
|
||||
html += chunk.toString('utf-8');
|
||||
callback();
|
||||
},
|
||||
destroy() {
|
||||
resolve(html);
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a while loop instead of "for await" due to cloudflare and Vercel Edge issues
|
||||
* See https://github.com/facebook/react/issues/24169
|
||||
|
|
Loading…
Reference in a new issue