Skip to content

Commit

Permalink
hide hostcontexttype by exposing a getter for ancestorInfo.resourceFo…
Browse files Browse the repository at this point in the history
…rmOnly
  • Loading branch information
gnoff committed Oct 22, 2022
1 parent 0fb69cf commit a066705
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/react-dom-bindings/src/client/ReactDOMFloatClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
...
Expand Down
7 changes: 6 additions & 1 deletion packages/react-dom-bindings/src/client/validateDOMNesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

let validateDOMNesting = () => {};
let updatedAncestorInfo = () => {};
let getResourceFormOnly = () => false;

if (__DEV__) {
// This validation code was written based on the HTML5 parsing spec:
Expand Down Expand Up @@ -478,6 +479,10 @@ if (__DEV__) {
);
}
};

getResourceFormOnly = hostContextDev => {
return hostContextDev.ancestorInfo.resourceFormOnly;
};
}

export {updatedAncestorInfo, validateDOMNesting};
export {updatedAncestorInfo, validateDOMNesting, getResourceFormOnly};

0 comments on commit a066705

Please sign in to comment.