Skip to content

Commit

Permalink
fix: hot render of forward props component
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jun 15, 2019
1 parent 2fafd44 commit 4ba7530
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/internal/stack/hydrateFiberStack.js
@@ -1,7 +1,7 @@
/* eslint-disable no-underscore-dangle */
import ReactDOM from 'react-dom';

const hotRenderWithHooks = ReactDOM.hotRenderWithHooks || ((fiber, render) => render());
export const hotRenderWithHooks = ReactDOM.hotRenderWithHooks || ((fiber, render) => render());

function pushStack(stack, node) {
stack.type = node.type;
Expand Down
8 changes: 5 additions & 3 deletions src/reconciler/hotReplacementRender.js
Expand Up @@ -18,6 +18,7 @@ import logger from '../logger';
import configuration, { internalConfiguration } from '../configuration';
import { areSwappable } from './utils';
import { resolveType } from './resolver';
import { hotRenderWithHooks } from '../internal/stack/hydrateFiberStack';

let renderStack = [];

Expand Down Expand Up @@ -51,7 +52,7 @@ const unflatten = a =>
const isArray = fn => Array.isArray(fn);
const asArray = a => (isArray(a) ? a : [a]);

const render = component => {
const render = (component, stack) => {
if (!component) {
return [];
}
Expand All @@ -64,7 +65,8 @@ const render = component => {
return component.hotComponentRender ? component.hotComponentRender() : component.render();
}
if (isForwardType(component)) {
return component.type.render(component.props, null);
// render forward type in a sandbox
return hotRenderWithHooks(stack.fiber, () => component.type.render(component.props, null));
}
if (isArray(component)) {
return component.map(render);
Expand Down Expand Up @@ -194,7 +196,7 @@ const hotReplacementRender = (instance, stack) => {
}

try {
const flow = transformFlowNode(filterNullArray(asArray(render(instance))));
const flow = transformFlowNode(filterNullArray(asArray(render(instance, stack))));

const { children } = stack;

Expand Down

0 comments on commit 4ba7530

Please sign in to comment.