From 0dfb986763b417fdfc1c67af81e4c2acc2faec84 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Mon, 5 Dec 2022 17:02:58 -0500 Subject: [PATCH] Revert "experimental_use(context) for server components and ssr (#25226)" This reverts commit 3613284dceac38de4ef5a7c93c4897600ee6923b. implements the experimental use(context) API for the server components (Flight) and SSR (Fizz) runtimes --- .../src/__tests__/ReactDOMFizzServer-test.js | 48 ------------------- packages/react-server/src/ReactFizzHooks.js | 14 ++---- 2 files changed, 3 insertions(+), 59 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js index 3707f61b82a48..3d00423c9a081 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js @@ -5215,54 +5215,6 @@ describe('ReactDOMFizzServer', () => { expect(getVisibleChildren(container)).toEqual('ABC'); }); - // @gate enableUseHook - it('basic use(context)', async () => { - const ContextA = React.createContext('default'); - const ContextB = React.createContext('B'); - const ServerContext = React.createServerContext( - 'ServerContext', - 'default', - ); - function Client() { - return use(ContextA) + use(ContextB); - } - function ServerComponent() { - return use(ServerContext); - } - function Server() { - return ( - - - - ); - } - function App() { - return ( - <> - - - - - - ); - } - - await act(async () => { - const {pipe} = renderToPipeableStream(); - pipe(writable); - }); - expect(getVisibleChildren(container)).toEqual(['AB', 'C']); - - // Hydration uses a different renderer runtime (Fiber instead of Fizz). - // We reset _currentRenderer here to not trigger a warning about multiple - // renderers concurrently using these contexts - ContextA._currentRenderer = null; - ServerContext._currentRenderer = null; - ReactDOMClient.hydrateRoot(container, ); - expect(Scheduler).toFlushAndYield([]); - expect(getVisibleChildren(container)).toEqual(['AB', 'C']); - }); - // @gate enableUseHook it('use(promise) in multiple components', async () => { const promiseA = Promise.resolve('A'); diff --git a/packages/react-server/src/ReactFizzHooks.js b/packages/react-server/src/ReactFizzHooks.js index f404a71c6ad5f..39f0af172fabe 100644 --- a/packages/react-server/src/ReactFizzHooks.js +++ b/packages/react-server/src/ReactFizzHooks.js @@ -40,11 +40,7 @@ import { enableUseMemoCacheHook, } from 'shared/ReactFeatureFlags'; import is from 'shared/objectIs'; -import { - REACT_SERVER_CONTEXT_TYPE, - REACT_CONTEXT_TYPE, - REACT_MEMO_CACHE_SENTINEL, -} from 'shared/ReactSymbols'; +import {REACT_MEMO_CACHE_SENTINEL} from 'shared/ReactSymbols'; type BasicStateAction = (S => S) | S; type Dispatch = A => void; @@ -648,12 +644,8 @@ function use(usable: Usable): T { } } } - } else if ( - usable.$$typeof === REACT_CONTEXT_TYPE || - usable.$$typeof === REACT_SERVER_CONTEXT_TYPE - ) { - const context: ReactContext = (usable: any); - return readContext(context); + } else { + // TODO: Add support for Context } }