mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Clean up partial renderer entry points (#21682)
* Clean up partial renderer entry points I made a mistake by leaving server.browser.stable in which is the partial renderer for the browser build of stable. That should use the legacy fizz one. Since the only usage of the partial renderer now is at FB and we don't use it with Node, I removed the Node build of partial renderer too. * Remove GC test No code is running this path anymore. Ideally this should be ported to a Fizz form.
This commit is contained in:
committed by
GitHub
parent
955ae55529
commit
950dae4e27
@@ -13,4 +13,4 @@ export {
|
||||
renderToNodeStream,
|
||||
renderToStaticNodeStream,
|
||||
version,
|
||||
} from './src/server/ReactDOMServerBrowser';
|
||||
} from './src/server/ReactDOMServerLegacyPartialRendererBrowser';
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
export {
|
||||
renderToString,
|
||||
renderToStaticMarkup,
|
||||
renderToNodeStream,
|
||||
renderToStaticNodeStream,
|
||||
version,
|
||||
} from './src/server/ReactDOMServerBrowser';
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
// For some reason Flow doesn't like export * in this file. I don't know why.
|
||||
export {
|
||||
renderToString,
|
||||
renderToStaticMarkup,
|
||||
renderToNodeStream,
|
||||
renderToStaticNodeStream,
|
||||
version,
|
||||
} from './src/server/ReactDOMServerNode';
|
||||
@@ -486,77 +486,6 @@ describe('ReactDOMServerIntegration', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/facebook/react/issues/14705
|
||||
// @gate !experimental && www
|
||||
it('does not pollute later renders when stream destroyed', () => {
|
||||
const LoggedInUser = React.createContext('default');
|
||||
|
||||
const AppWithUser = user => (
|
||||
<LoggedInUser.Provider value={user}>
|
||||
<header>
|
||||
<LoggedInUser.Consumer>{whoAmI => whoAmI}</LoggedInUser.Consumer>
|
||||
</header>
|
||||
</LoggedInUser.Provider>
|
||||
);
|
||||
|
||||
const stream = ReactDOMServer.renderToNodeStream(
|
||||
AppWithUser('Amy'),
|
||||
).setEncoding('utf8');
|
||||
|
||||
// This is an implementation detail because we test a memory leak
|
||||
const {threadID} = stream.partialRenderer;
|
||||
|
||||
// Read enough to render Provider but not enough for it to be exited
|
||||
stream._read(10);
|
||||
expect(LoggedInUser[threadID]).toBe('Amy');
|
||||
|
||||
stream.destroy();
|
||||
|
||||
const AppWithUserNoProvider = () => (
|
||||
<LoggedInUser.Consumer>{whoAmI => whoAmI}</LoggedInUser.Consumer>
|
||||
);
|
||||
|
||||
const stream2 = ReactDOMServer.renderToNodeStream(
|
||||
AppWithUserNoProvider(),
|
||||
).setEncoding('utf8');
|
||||
|
||||
// Sanity check to ensure 2nd render has same threadID as 1st render,
|
||||
// otherwise this test is not testing what it's meant to
|
||||
expect(stream2.partialRenderer.threadID).toBe(threadID);
|
||||
|
||||
const markup = stream2.read(Infinity);
|
||||
|
||||
expect(markup).toBe('default');
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/facebook/react/issues/14705
|
||||
// @gate !experimental && www
|
||||
it('frees context value reference when stream destroyed', () => {
|
||||
const LoggedInUser = React.createContext('default');
|
||||
|
||||
const AppWithUser = user => (
|
||||
<LoggedInUser.Provider value={user}>
|
||||
<header>
|
||||
<LoggedInUser.Consumer>{whoAmI => whoAmI}</LoggedInUser.Consumer>
|
||||
</header>
|
||||
</LoggedInUser.Provider>
|
||||
);
|
||||
|
||||
const stream = ReactDOMServer.renderToNodeStream(
|
||||
AppWithUser('Amy'),
|
||||
).setEncoding('utf8');
|
||||
|
||||
// This is an implementation detail because we test a memory leak
|
||||
const {threadID} = stream.partialRenderer;
|
||||
|
||||
// Read enough to render Provider but not enough for it to be exited
|
||||
stream._read(10);
|
||||
expect(LoggedInUser[threadID]).toBe('Amy');
|
||||
|
||||
stream.destroy();
|
||||
expect(LoggedInUser[threadID]).toBe('default');
|
||||
});
|
||||
|
||||
it('does not pollute sync renders after an error', () => {
|
||||
const LoggedInUser = React.createContext('default');
|
||||
const Crash = () => {
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import type {ServerOptions} from './ReactPartialRenderer';
|
||||
|
||||
import {Readable} from 'stream';
|
||||
|
||||
import ReactPartialRenderer from './ReactPartialRenderer';
|
||||
|
||||
// This is a Readable Node.js stream which wraps the ReactDOMPartialRenderer.
|
||||
class ReactMarkupReadableStream extends Readable {
|
||||
constructor(element, makeStaticMarkup, options) {
|
||||
// Calls the stream.Readable(options) constructor. Consider exposing built-in
|
||||
// features like highWaterMark in the future.
|
||||
super({});
|
||||
this.partialRenderer = new ReactPartialRenderer(
|
||||
element,
|
||||
makeStaticMarkup,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
_destroy(err, callback) {
|
||||
this.partialRenderer.destroy();
|
||||
callback(err);
|
||||
}
|
||||
|
||||
_read(size) {
|
||||
try {
|
||||
this.push(this.partialRenderer.read(size));
|
||||
} catch (err) {
|
||||
this.destroy(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Render a ReactElement to its initial HTML. This should only be used on the
|
||||
* server.
|
||||
* See https://reactjs.org/docs/react-dom-server.html#rendertonodestream
|
||||
*/
|
||||
export function renderToNodeStream(element, options?: ServerOptions) {
|
||||
return new ReactMarkupReadableStream(element, false, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to renderToNodeStream, except this doesn't create extra DOM attributes
|
||||
* such as data-react-id that React uses internally.
|
||||
* See https://reactjs.org/docs/react-dom-server.html#rendertostaticnodestream
|
||||
*/
|
||||
export function renderToStaticNodeStream(element, options?: ServerOptions) {
|
||||
return new ReactMarkupReadableStream(element, true, options);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import ReactVersion from 'shared/ReactVersion';
|
||||
|
||||
import {renderToString, renderToStaticMarkup} from './ReactDOMStringRenderer';
|
||||
import {
|
||||
renderToNodeStream,
|
||||
renderToStaticNodeStream,
|
||||
} from './ReactDOMNodeStreamRenderer';
|
||||
|
||||
export {
|
||||
renderToString,
|
||||
renderToStaticMarkup,
|
||||
renderToNodeStream,
|
||||
renderToStaticNodeStream,
|
||||
ReactVersion as version,
|
||||
};
|
||||
@@ -20,7 +20,6 @@ module.exports = [
|
||||
'react-dom',
|
||||
'react-dom/unstable-fizz',
|
||||
'react-dom/unstable-fizz.node',
|
||||
'react-dom/server.node.stable',
|
||||
'react-dom/src/server/ReactDOMFizzServerNode.js', // react-dom/unstable-fizz.node
|
||||
'react-server-dom-webpack',
|
||||
'react-server-dom-webpack/writer',
|
||||
@@ -45,7 +44,6 @@ module.exports = [
|
||||
'react-dom',
|
||||
'react-dom/testing',
|
||||
'react-dom/unstable-fizz.browser',
|
||||
'react-dom/server.browser.stable',
|
||||
'react-dom/src/server/ReactDOMFizzServerBrowser.js', // react-dom/unstable-fizz.browser
|
||||
'react-server-dom-webpack',
|
||||
'react-server-dom-webpack/writer.browser.server',
|
||||
|
||||
Reference in New Issue
Block a user