Skip to content

Commit 2099a2a

Browse files
committed
Read ownerDocument from the root container instance
This way createInstance() depends on the innermost container only for reading the namespace.
1 parent 94cd7db commit 2099a2a

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/renderers/dom/fiber/ReactDOMFiber.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ var DOMRenderer = ReactFiberReconciler({
8181
createInstance(
8282
type : string,
8383
props : Props,
84+
rootContainerInstance : Container,
8485
containerInstance : Instance | Container,
8586
internalInstanceHandle : Object,
8687
) : Instance {
87-
const domElement : Instance = createElement(type, props, containerInstance);
88+
const domElement : Instance = createElement(type, props, rootContainerInstance, containerInstance);
8889
precacheFiberNode(internalInstanceHandle, domElement);
8990
return domElement;
9091
},

src/renderers/dom/fiber/ReactDOMFiberComponent.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,19 +467,20 @@ var ReactDOMFiberComponent = {
467467
createElement(
468468
type : string,
469469
props : Object,
470-
rootContainerElement : Element
470+
rootContainerElement : Element,
471+
containerElement : Element
471472
) : Element {
472473
validateDangerousTag(type);
473474
// TODO:
474475
// const tag = type.toLowerCase(); Do we need to apply lower case only on non-custom elements?
475476

476477
// We create tags in the namespace of their parent container, except HTML
477478
// tags get no namespace.
478-
var namespaceURI = rootContainerElement.namespaceURI;
479+
var namespaceURI = containerElement.namespaceURI;
479480
if (namespaceURI == null ||
480481
namespaceURI === DOMNamespaces.svg &&
481482
// We don't need convert to lowercase because SVG is case sensitive:
482-
rootContainerElement.tagName === 'foreignObject') {
483+
containerElement.tagName === 'foreignObject') {
483484
namespaceURI = DOMNamespaces.html;
484485
}
485486
if (namespaceURI === DOMNamespaces.html) {

src/renderers/shared/fiber/ReactFiberBeginWork.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ module.exports = function<T, P, I, TI, C>(
7272

7373
const {
7474
getHostContainerOnStack,
75+
getRootHostContainerOnStack,
7576
pushHostContainer,
7677
saveHostContextToPortal,
7778
} = hostContext;
@@ -234,8 +235,18 @@ module.exports = function<T, P, I, TI, C>(
234235
}
235236
if (!current && workInProgress.stateNode == null) {
236237
const newProps = workInProgress.pendingProps;
237-
const hostContainer = getHostContainerOnStack();
238-
const instance = createInstance(workInProgress.type, newProps, hostContainer, workInProgress);
238+
const containerInstance = getHostContainerOnStack();
239+
const rootContainerInstance = getRootHostContainerOnStack();
240+
if (rootContainerInstance == null) {
241+
throw new Error('Expected to find a root instance on the host stack.');
242+
}
243+
const instance = createInstance(
244+
workInProgress.type,
245+
newProps,
246+
rootContainerInstance,
247+
containerInstance,
248+
workInProgress
249+
);
239250
workInProgress.stateNode = instance;
240251
}
241252
if (workInProgress.pendingProps.hidden &&

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type HostConfig<T, P, I, TI, C> = {
4444

4545
isContainerType(type : T) : boolean,
4646

47-
createInstance(type : T, props : P, containerInstance : I | C, internalInstanceHandle : OpaqueNode) : I,
47+
createInstance(type : T, props : P, rootContainerInstance : C, containerInstance : I | C, internalInstanceHandle : OpaqueNode) : I,
4848
appendInitialChild(parentInstance : I, child : I | TI) : void,
4949
finalizeInitialChildren(parentInstance : I, props : P, rootContainerInstance : C) : void,
5050

0 commit comments

Comments
 (0)