From fd89f83db8434e026384a977f19ce0cbc3130d32 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 26 Apr 2021 21:56:42 -0400 Subject: [PATCH] Swap the primary renderer flag in the legacy stream config This allows the legacy implementation to co-exist with the new implementation. But primarily it allows Fiber and the legacy renderToString to co-exist. --- .../react-dom/src/server/ReactDOMLegacyServerStreamConfig.js | 2 ++ packages/react-dom/src/server/ReactDOMServerFormatConfig.js | 3 ++- packages/react-server/src/ReactServerStreamConfigBrowser.js | 2 ++ packages/react-server/src/ReactServerStreamConfigNode.js | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/react-dom/src/server/ReactDOMLegacyServerStreamConfig.js b/packages/react-dom/src/server/ReactDOMLegacyServerStreamConfig.js index 4cfe16091bc58..c1d6c1df07ef9 100644 --- a/packages/react-dom/src/server/ReactDOMLegacyServerStreamConfig.js +++ b/packages/react-dom/src/server/ReactDOMLegacyServerStreamConfig.js @@ -16,6 +16,8 @@ export type Destination = { export type PrecomputedChunk = string; export type Chunk = string; +export const isPrimaryStreamConfig = false; + export function scheduleWork(callback: () => void) { callback(); } diff --git a/packages/react-dom/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom/src/server/ReactDOMServerFormatConfig.js index 72e984f12824b..3e77b7ce35a8e 100644 --- a/packages/react-dom/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom/src/server/ReactDOMServerFormatConfig.js @@ -23,6 +23,7 @@ import { writeChunk, stringToChunk, stringToPrecomputedChunk, + isPrimaryStreamConfig, } from 'react-server/src/ReactServerStreamConfig'; import { @@ -50,7 +51,7 @@ import isArray from 'shared/isArray'; // Used to distinguish these contexts from ones used in other renderers. // E.g. this can be used to distinguish legacy renderers from this modern one. -export const isPrimaryRenderer = true; +export const isPrimaryRenderer = isPrimaryStreamConfig; // Per response, global state that is not contextual to the rendering subtree. export type ResponseState = { diff --git a/packages/react-server/src/ReactServerStreamConfigBrowser.js b/packages/react-server/src/ReactServerStreamConfigBrowser.js index 3714be4302765..b669002aff771 100644 --- a/packages/react-server/src/ReactServerStreamConfigBrowser.js +++ b/packages/react-server/src/ReactServerStreamConfigBrowser.js @@ -12,6 +12,8 @@ export type Destination = ReadableStreamController; export type PrecomputedChunk = Uint8Array; export type Chunk = Uint8Array; +export const isPrimaryStreamConfig = true; + export function scheduleWork(callback: () => void) { callback(); } diff --git a/packages/react-server/src/ReactServerStreamConfigNode.js b/packages/react-server/src/ReactServerStreamConfigNode.js index 4329554b7f050..c44d5b8ee6566 100644 --- a/packages/react-server/src/ReactServerStreamConfigNode.js +++ b/packages/react-server/src/ReactServerStreamConfigNode.js @@ -21,6 +21,8 @@ export type Destination = Writable & MightBeFlushable; export type PrecomputedChunk = Uint8Array; export type Chunk = string; +export const isPrimaryStreamConfig = true; + export function scheduleWork(callback: () => void) { setImmediate(callback); }