Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove renderToStaticNodeStream #28873

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-dom/npm/server.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/npm/server.bun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 0 additions & 1 deletion packages/react-dom/npm/server.edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/npm/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions packages/react-dom/server.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 0 additions & 7 deletions packages/react-dom/server.bun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions packages/react-dom/server.edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions packages/react-dom/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
67 changes: 0 additions & 67 deletions packages/react-dom/src/__tests__/ReactServerRendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 1 addition & 12 deletions packages/react-dom/src/server/ReactDOMFizzServerBun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
14 changes: 1 addition & 13 deletions packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
8 changes: 1 addition & 7 deletions packages/react-dom/src/server/ReactDOMLegacyServerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import type {ReactNodeList} from 'shared/ReactTypes';

import {version, renderToStringImpl} from './ReactDOMLegacyServerImpl';
import {renderToStaticNodeStream} from './ReactDOMLegacyServerNodeStream';

type ServerOptions = {
identifierPrefix?: string,
Expand Down Expand Up @@ -40,9 +39,4 @@ function renderToStaticMarkup(
);
}

export {
renderToString,
renderToStaticMarkup,
renderToStaticNodeStream,
version,
};
export {renderToString, renderToStaticMarkup, version};
Loading