mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Remove renderToStaticNodeStream (#28873)
Stacked on #28872 renderToStaticNodeStream was not originally deprecated when renderToNodeStream was deprecated because it did not yet have a clear analog in the modern streaming implementation for SSR. In React 19 we have already removed renderToNodeStream. This change removes renderToStaticNodeStream as well because you can replicate it's semantics using renderToPipeableStream with onAllReady or renderToReadableStream with await stream.allready.
This commit is contained in:
@@ -12,7 +12,6 @@ if (process.env.NODE_ENV === 'production') {
|
||||
exports.version = l.version;
|
||||
exports.renderToString = l.renderToString;
|
||||
exports.renderToStaticMarkup = l.renderToStaticMarkup;
|
||||
exports.renderToStaticNodeStream = l.renderToStaticNodeStream;
|
||||
exports.renderToReadableStream = s.renderToReadableStream;
|
||||
if (s.resume) {
|
||||
exports.resume = s.resume;
|
||||
|
||||
@@ -15,6 +15,5 @@ exports.renderToReadableStream = b.renderToReadableStream;
|
||||
if (b.resume) {
|
||||
exports.resume = b.resume;
|
||||
}
|
||||
exports.renderToStaticNodeStream = b.renderToStaticNodeStream;
|
||||
exports.renderToString = l.renderToString;
|
||||
exports.renderToStaticMarkup = l.renderToStaticMarkup;
|
||||
|
||||
@@ -12,7 +12,6 @@ if (process.env.NODE_ENV === 'production') {
|
||||
|
||||
exports.version = b.version;
|
||||
exports.renderToReadableStream = b.renderToReadableStream;
|
||||
exports.renderToStaticNodeStream = b.renderToStaticNodeStream;
|
||||
exports.renderToString = l.renderToString;
|
||||
exports.renderToStaticMarkup = l.renderToStaticMarkup;
|
||||
if (b.resume) {
|
||||
|
||||
@@ -12,7 +12,6 @@ if (process.env.NODE_ENV === 'production') {
|
||||
exports.version = l.version;
|
||||
exports.renderToString = l.renderToString;
|
||||
exports.renderToStaticMarkup = l.renderToStaticMarkup;
|
||||
exports.renderToStaticNodeStream = l.renderToStaticNodeStream;
|
||||
exports.renderToPipeableStream = s.renderToPipeableStream;
|
||||
if (s.resumeToPipeableStream) {
|
||||
exports.resumeToPipeableStream = s.resumeToPipeableStream;
|
||||
|
||||
@@ -23,12 +23,6 @@ export function renderToStaticMarkup() {
|
||||
arguments,
|
||||
);
|
||||
}
|
||||
export function renderToStaticNodeStream() {
|
||||
return require('./src/server/ReactDOMLegacyServerBrowser').renderToStaticNodeStream.apply(
|
||||
this,
|
||||
arguments,
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToReadableStream() {
|
||||
return require('./src/server/react-dom-server.browser').renderToReadableStream.apply(
|
||||
|
||||
@@ -18,13 +18,6 @@ export function renderToReadableStream() {
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToStaticNodeStream() {
|
||||
return require('./src/server/react-dom-server.bun').renderToStaticNodeStream.apply(
|
||||
this,
|
||||
arguments,
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToString() {
|
||||
return require('./src/server/ReactDOMLegacyServerBrowser').renderToString.apply(
|
||||
this,
|
||||
|
||||
@@ -18,13 +18,6 @@ export function renderToReadableStream() {
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToStaticNodeStream() {
|
||||
return require('./src/server/react-dom-server.edge').renderToStaticNodeStream.apply(
|
||||
this,
|
||||
arguments,
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToString() {
|
||||
return require('./src/server/ReactDOMLegacyServerBrowser').renderToString.apply(
|
||||
this,
|
||||
|
||||
@@ -23,12 +23,6 @@ export function renderToStaticMarkup() {
|
||||
arguments,
|
||||
);
|
||||
}
|
||||
export function renderToStaticNodeStream() {
|
||||
return require('./src/server/ReactDOMLegacyServerNode').renderToStaticNodeStream.apply(
|
||||
this,
|
||||
arguments,
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToPipeableStream() {
|
||||
return require('./src/server/react-dom-server.node').renderToPipeableStream.apply(
|
||||
|
||||
@@ -324,97 +324,6 @@ describe('ReactDOMServerIntegration', () => {
|
||||
expect(e.textContent).toBe('dark');
|
||||
});
|
||||
|
||||
it('does not pollute parallel node streams', () => {
|
||||
const LoggedInUser = React.createContext();
|
||||
|
||||
const AppWithUser = user => (
|
||||
<LoggedInUser.Provider value={user}>
|
||||
<header>
|
||||
<LoggedInUser.Consumer>{whoAmI => whoAmI}</LoggedInUser.Consumer>
|
||||
</header>
|
||||
<footer>
|
||||
<LoggedInUser.Consumer>{whoAmI => whoAmI}</LoggedInUser.Consumer>
|
||||
</footer>
|
||||
</LoggedInUser.Provider>
|
||||
);
|
||||
|
||||
const streamAmy = ReactDOMServer.renderToStaticNodeStream(
|
||||
AppWithUser('Amy'),
|
||||
).setEncoding('utf8');
|
||||
const streamBob = ReactDOMServer.renderToStaticNodeStream(
|
||||
AppWithUser('Bob'),
|
||||
).setEncoding('utf8');
|
||||
|
||||
// Testing by filling the buffer using internal _read() with a small
|
||||
// number of bytes to avoid a test case which needs to align to a
|
||||
// highWaterMark boundary of 2^14 chars.
|
||||
streamAmy._read(20);
|
||||
streamBob._read(20);
|
||||
streamAmy._read(20);
|
||||
streamBob._read(20);
|
||||
|
||||
expect(streamAmy.read()).toBe('<header>Amy</header><footer>Amy</footer>');
|
||||
expect(streamBob.read()).toBe('<header>Bob</header><footer>Bob</footer>');
|
||||
});
|
||||
|
||||
it('does not pollute parallel node streams when many are used', () => {
|
||||
const CurrentIndex = React.createContext();
|
||||
|
||||
const NthRender = index => (
|
||||
<CurrentIndex.Provider value={index}>
|
||||
<header>
|
||||
<CurrentIndex.Consumer>{idx => idx}</CurrentIndex.Consumer>
|
||||
</header>
|
||||
<footer>
|
||||
<CurrentIndex.Consumer>{idx => idx}</CurrentIndex.Consumer>
|
||||
</footer>
|
||||
</CurrentIndex.Provider>
|
||||
);
|
||||
|
||||
const streams = [];
|
||||
|
||||
// Test with more than 32 streams to test that growing the thread count
|
||||
// works properly.
|
||||
const streamCount = 34;
|
||||
|
||||
for (let i = 0; i < streamCount; i++) {
|
||||
streams[i] = ReactDOMServer.renderToStaticNodeStream(
|
||||
NthRender(i % 2 === 0 ? 'Expected to be recreated' : i),
|
||||
).setEncoding('utf8');
|
||||
}
|
||||
|
||||
// Testing by filling the buffer using internal _read() with a small
|
||||
// number of bytes to avoid a test case which needs to align to a
|
||||
// highWaterMark boundary of 2^14 chars.
|
||||
for (let i = 0; i < streamCount; i++) {
|
||||
streams[i]._read(20);
|
||||
}
|
||||
|
||||
// Early destroy every other stream
|
||||
for (let i = 0; i < streamCount; i += 2) {
|
||||
streams[i].destroy();
|
||||
}
|
||||
|
||||
// Recreate those same streams.
|
||||
for (let i = 0; i < streamCount; i += 2) {
|
||||
streams[i] = ReactDOMServer.renderToStaticNodeStream(
|
||||
NthRender(i),
|
||||
).setEncoding('utf8');
|
||||
}
|
||||
|
||||
// Read a bit from all streams again.
|
||||
for (let i = 0; i < streamCount; i++) {
|
||||
streams[i]._read(20);
|
||||
}
|
||||
|
||||
// Assert that all stream rendered the expected output.
|
||||
for (let i = 0; i < streamCount; i++) {
|
||||
expect(streams[i].read()).toBe(
|
||||
'<header>' + i + '</header><footer>' + i + '</footer>',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not pollute sync renders after an error', () => {
|
||||
const LoggedInUser = React.createContext('default');
|
||||
const Crash = () => {
|
||||
|
||||
@@ -577,73 +577,6 @@ describe('ReactDOMServer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderToStaticNodeStream', () => {
|
||||
it('should generate simple markup', () => {
|
||||
const SuccessfulElement = React.createElement(() => <img />);
|
||||
expect(() => {
|
||||
const response =
|
||||
ReactDOMServer.renderToStaticNodeStream(SuccessfulElement);
|
||||
expect(response.read().toString()).toMatch(new RegExp('<img' + '/>'));
|
||||
}).toErrorDev(
|
||||
'ReactDOMServer.renderToStaticNodeStream() is deprecated and will be removed in an upcomingrelease of React',
|
||||
{withoutStack: true},
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle errors correctly', () => {
|
||||
const FailingElement = React.createElement(() => {
|
||||
throw new Error('An Error');
|
||||
});
|
||||
|
||||
let response;
|
||||
expect(() => {
|
||||
response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
|
||||
}).toErrorDev(
|
||||
'ReactDOMServer.renderToStaticNodeStream() is deprecated and will be removed in an upcomingrelease of React',
|
||||
{withoutStack: true},
|
||||
);
|
||||
return new Promise(resolve => {
|
||||
response.once('error', () => {
|
||||
resolve();
|
||||
});
|
||||
expect(response.read()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it('should omit text and suspense placeholders', async () => {
|
||||
let resolve = null;
|
||||
const promise = new Promise(res => {
|
||||
resolve = () => {
|
||||
resolved = true;
|
||||
res();
|
||||
};
|
||||
});
|
||||
let resolved = false;
|
||||
function Suspender() {
|
||||
if (resolved) {
|
||||
return 'resolved';
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
|
||||
let response;
|
||||
expect(() => {
|
||||
response = ReactDOMServer.renderToStaticNodeStream(
|
||||
<div>
|
||||
<React.Suspense fallback={'fallback'}>
|
||||
<Suspender />
|
||||
</React.Suspense>
|
||||
</div>,
|
||||
);
|
||||
}).toErrorDev(
|
||||
'ReactDOMServer.renderToStaticNodeStream() is deprecated and will be removed in an upcomingrelease of React',
|
||||
{withoutStack: true},
|
||||
);
|
||||
await resolve();
|
||||
expect(response.read().toString()).toEqual('<div>resolved</div>');
|
||||
});
|
||||
});
|
||||
|
||||
it('warns with a no-op when an async setState is triggered', () => {
|
||||
class Foo extends React.Component {
|
||||
UNSAFE_componentWillMount() {
|
||||
|
||||
+1
-12
@@ -146,15 +146,4 @@ function renderToReadableStream(
|
||||
});
|
||||
}
|
||||
|
||||
function renderToStaticNodeStream() {
|
||||
throw new Error(
|
||||
'ReactDOMServer.renderToStaticNodeStream(): The Node Stream API is not available ' +
|
||||
'in Bun. Use ReactDOMServer.renderToReadableStream() instead.',
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
renderToReadableStream,
|
||||
renderToStaticNodeStream,
|
||||
ReactVersion as version,
|
||||
};
|
||||
export {renderToReadableStream, ReactVersion as version};
|
||||
|
||||
@@ -39,16 +39,4 @@ function renderToStaticMarkup(
|
||||
);
|
||||
}
|
||||
|
||||
function renderToStaticNodeStream() {
|
||||
throw new Error(
|
||||
'ReactDOMServer.renderToStaticNodeStream(): The streaming API is not available ' +
|
||||
'in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.',
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
renderToString,
|
||||
renderToStaticMarkup,
|
||||
renderToStaticNodeStream,
|
||||
version,
|
||||
};
|
||||
export {renderToString, renderToStaticMarkup, version};
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
import type {ReactNodeList} from 'shared/ReactTypes';
|
||||
|
||||
import {version, renderToStringImpl} from './ReactDOMLegacyServerImpl';
|
||||
import {renderToStaticNodeStream} from './ReactDOMLegacyServerNodeStream';
|
||||
|
||||
type ServerOptions = {
|
||||
identifierPrefix?: string,
|
||||
@@ -40,9 +39,4 @@ function renderToStaticMarkup(
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
renderToString,
|
||||
renderToStaticMarkup,
|
||||
renderToStaticNodeStream,
|
||||
version,
|
||||
};
|
||||
export {renderToString, renderToStaticMarkup, version};
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {ReactNodeList} from 'shared/ReactTypes';
|
||||
|
||||
import type {Request} from 'react-server/src/ReactFizzServer';
|
||||
|
||||
import {
|
||||
createRequest,
|
||||
startWork,
|
||||
startFlowing,
|
||||
abort,
|
||||
} from 'react-server/src/ReactFizzServer';
|
||||
|
||||
import {
|
||||
createResumableState,
|
||||
createRenderState,
|
||||
createRootFormatContext,
|
||||
} from 'react-dom-bindings/src/server/ReactFizzConfigDOMLegacy';
|
||||
|
||||
import {Readable} from 'stream';
|
||||
|
||||
type ServerOptions = {
|
||||
identifierPrefix?: string,
|
||||
};
|
||||
|
||||
class ReactMarkupReadableStream extends Readable {
|
||||
request: Request;
|
||||
startedFlowing: boolean;
|
||||
constructor() {
|
||||
// Calls the stream.Readable(options) constructor. Consider exposing built-in
|
||||
// features like highWaterMark in the future.
|
||||
super({});
|
||||
this.request = (null: any);
|
||||
this.startedFlowing = false;
|
||||
}
|
||||
|
||||
// $FlowFixMe[missing-local-annot]
|
||||
_destroy(err, callback) {
|
||||
abort(this.request);
|
||||
callback(err);
|
||||
}
|
||||
|
||||
// $FlowFixMe[missing-local-annot]
|
||||
_read(size) {
|
||||
if (this.startedFlowing) {
|
||||
startFlowing(this.request, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onError() {
|
||||
// Non-fatal errors are ignored.
|
||||
}
|
||||
|
||||
let didWarnAboutDeprecatedRenderToStaticNodeStream = false;
|
||||
|
||||
function renderToStaticNodeStream(
|
||||
children: ReactNodeList,
|
||||
options?: ServerOptions,
|
||||
): Readable {
|
||||
if (__DEV__) {
|
||||
if (!didWarnAboutDeprecatedRenderToStaticNodeStream) {
|
||||
didWarnAboutDeprecatedRenderToStaticNodeStream = true;
|
||||
console.error(
|
||||
'ReactDOMServer.renderToStaticNodeStream() is deprecated and will be removed in an upcoming' +
|
||||
'release of React. Use ReactDOMServer.renderToPipeableStream() and wait to `pipe` until the `onAllReady`' +
|
||||
' callback has been called to produce a document suitable for static use cases.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function onAllReady() {
|
||||
// We wait until everything has loaded before starting to write.
|
||||
// That way we only end up with fully resolved HTML even if we suspend.
|
||||
destination.startedFlowing = true;
|
||||
startFlowing(request, destination);
|
||||
}
|
||||
const destination = new ReactMarkupReadableStream();
|
||||
const resumableState = createResumableState(
|
||||
options ? options.identifierPrefix : undefined,
|
||||
undefined,
|
||||
);
|
||||
const request = createRequest(
|
||||
children,
|
||||
resumableState,
|
||||
createRenderState(resumableState, true),
|
||||
createRootFormatContext(),
|
||||
Infinity,
|
||||
onError,
|
||||
onAllReady,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
);
|
||||
destination.request = request;
|
||||
startWork(request);
|
||||
return destination;
|
||||
}
|
||||
|
||||
export {renderToStaticNodeStream};
|
||||
@@ -7,8 +7,4 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
export {
|
||||
renderToReadableStream,
|
||||
renderToStaticNodeStream,
|
||||
version,
|
||||
} from './ReactDOMFizzServerBun.js';
|
||||
export {renderToReadableStream, version} from './ReactDOMFizzServerBun.js';
|
||||
|
||||
Reference in New Issue
Block a user