Skip to content

DevTools: fork FastRefresh test for <18 versions of React #31893

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

Merged
merged 1 commit into from
Jan 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,83 @@ describe('Fast Refresh', () => {
expect(getContainer().firstChild).not.toBe(element);
});

// @reactVersion < 18.0
// @reactVersion >= 16.9
it('should not break when there are warnings in between patching', () => {
it('should not break when there are warnings in between patching (before post commit hook)', () => {
withErrorsOrWarningsIgnored(['Expected:'], () => {
render(`
const {useState} = React;

export default function Component() {
const [state, setState] = useState(1);
console.warn("Expected: warning during render");
return null;
}
`);
});
expect(store).toMatchInlineSnapshot(`
✕ 0, ⚠ 1
[root]
<Component> ⚠
`);

withErrorsOrWarningsIgnored(['Expected:'], () => {
patch(`
const {useEffect, useState} = React;

export default function Component() {
const [state, setState] = useState(1);
console.warn("Expected: warning during render");
return null;
}
`);
});
expect(store).toMatchInlineSnapshot(`
✕ 0, ⚠ 2
[root]
<Component> ⚠
`);

withErrorsOrWarningsIgnored(['Expected:'], () => {
patch(`
const {useEffect, useState} = React;

export default function Component() {
const [state, setState] = useState(1);
useEffect(() => {
console.error("Expected: error during effect");
});
console.warn("Expected: warning during render");
return null;
}
`);
});
expect(store).toMatchInlineSnapshot(`
✕ 0, ⚠ 1
[root]
<Component> ⚠
`);

withErrorsOrWarningsIgnored(['Expected:'], () => {
patch(`
const {useEffect, useState} = React;

export default function Component() {
const [state, setState] = useState(1);
console.warn("Expected: warning during render");
return null;
}
`);
});
expect(store).toMatchInlineSnapshot(`
✕ 0, ⚠ 1
[root]
<Component> ⚠
`);
});

// @reactVersion >= 18.0
it('should not break when there are warnings in between patching (with post commit hook)', () => {
withErrorsOrWarningsIgnored(['Expected:'], () => {
render(`
const {useState} = React;
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shared/src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ export function installHook(
checkDCE,
onCommitFiberUnmount,
onCommitFiberRoot,
// React v18.0+
onPostCommitFiberRoot,
setStrictMode,

Expand Down
Loading