Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fresh] Always remount classes #16823

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/react-reconciler/src/ReactFiberHotReloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ function scheduleFibersWithFamiliesRecursively(
if (staleFamilies.has(family)) {
needsRemount = true;
} else if (updatedFamilies.has(family)) {
needsRender = true;
if (tag === ClassComponent) {
needsRemount = true;
} else {
needsRender = true;
}
}
}
}
Expand Down
47 changes: 47 additions & 0 deletions packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,53 @@ describe('ReactFreshIntegration', () => {
}
});

it('remounts deprecated factory components', () => {
if (__DEV__) {
expect(() => {
render(`
function Parent() {
return {
render() {
return <Child prop="A" />;
}
};
};

function Child({prop}) {
return <h1>{prop}1</h1>;
};

export default Parent;
`);
}).toWarnDev(
'The <Parent /> component appears to be a function component ' +
'that returns a class instance.',
{withoutStack: true},
);
const el = container.firstChild;
expect(el.textContent).toBe('A1');
patch(`
function Parent() {
return {
render() {
return <Child prop="B" />;
}
};
};

function Child({prop}) {
return <h1>{prop}2</h1>;
};

export default Parent;
`);
// Like classes, factory components always remount.
expect(container.firstChild).not.toBe(el);
const newEl = container.firstChild;
expect(newEl.textContent).toBe('B2');
}
});

describe('with inline requires', () => {
beforeEach(() => {
global.FakeModuleSystem = {};
Expand Down