From a06670514d5392b3a5f4bb5c01ff2d827ffec7bb Mon Sep 17 00:00:00 2001 From: Josh Story Date: Sat, 22 Oct 2022 15:10:21 -0700 Subject: [PATCH] hide hostcontexttype by exposing a getter for ancestorInfo.resourceFormOnly --- .../react-dom-bindings/src/client/ReactDOMFloatClient.js | 7 ++++--- .../react-dom-bindings/src/client/ReactDOMHostConfig.js | 2 +- .../react-dom-bindings/src/client/validateDOMNesting.js | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js b/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js index 4cbefaa41b962..58a73189ec9c0 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js +++ b/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js @@ -7,7 +7,7 @@ * @flow */ -import type {Instance, Container, HostContextDev} from './ReactDOMHostConfig'; +import type {Instance, Container} from './ReactDOMHostConfig'; import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals.js'; const {Dispatcher} = ReactDOMSharedInternals; @@ -33,6 +33,7 @@ import { getCurrentRootHostContainer, getHostContext, } from 'react-reconciler/src/ReactFiberHostContext'; +import {getResourceFormOnly} from './validateDOMNesting'; // The resource types we support. currently they match the form for the as argument. // In the future this may need to change, especially when modules / scripts are supported @@ -1336,8 +1337,8 @@ function insertResourceInstanceBefore( export function isHostResourceType(type: string, props: Props): boolean { let resourceFormOnly: boolean; if (__DEV__) { - const hostContextDev: HostContextDev = (getHostContext(): any); - resourceFormOnly = (hostContextDev.ancestorInfo: any).resourceFormOnly; + const hostContext = getHostContext(); + resourceFormOnly = getResourceFormOnly(hostContext); } switch (type) { case 'meta': diff --git a/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js b/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js index fa14f5eeb02ae..cfd3131e9ba9a 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js +++ b/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js @@ -133,7 +133,7 @@ export interface SuspenseInstance extends Comment { } export type HydratableInstance = Instance | TextInstance | SuspenseInstance; export type PublicInstance = Element | Text; -export type HostContextDev = { +type HostContextDev = { namespace: string, ancestorInfo: mixed, ... diff --git a/packages/react-dom-bindings/src/client/validateDOMNesting.js b/packages/react-dom-bindings/src/client/validateDOMNesting.js index a3984db6355b4..da6852276a9f2 100644 --- a/packages/react-dom-bindings/src/client/validateDOMNesting.js +++ b/packages/react-dom-bindings/src/client/validateDOMNesting.js @@ -7,6 +7,7 @@ let validateDOMNesting = () => {}; let updatedAncestorInfo = () => {}; +let getResourceFormOnly = () => false; if (__DEV__) { // This validation code was written based on the HTML5 parsing spec: @@ -478,6 +479,10 @@ if (__DEV__) { ); } }; + + getResourceFormOnly = hostContextDev => { + return hostContextDev.ancestorInfo.resourceFormOnly; + }; } -export {updatedAncestorInfo, validateDOMNesting}; +export {updatedAncestorInfo, validateDOMNesting, getResourceFormOnly};