Skip to content

test(react): wait for hmr update to reduce flakyness #459

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
Apr 16, 2025

Conversation

sapphi-red
Copy link
Member

Description

The following test failed some times in the following condition

test('should only hmr files with exported react components', async () => {
await untilBrowserLogAfter(
() =>
editFile('hmr/no-exported-comp.jsx', (code) =>
code.replace('An Object', 'Updated'),
),
[
new RegExp(
`^${escapeRegex(
'[vite] invalidate /hmr/no-exported-comp.jsx: Could not Fast Refresh ("Foo" export is incompatible). Learn more at https://github.com/vitejs/vite-plugin-react/tree/main/packages/',
)}plugin-react(?:-\\w+)?${escapeRegex(
'#consistent-components-exports',
)}`,
),
'[vite] hot updated: /hmr/no-exported-comp.jsx',
'[vite] hot updated: /hmr/parent.jsx',
'Parent rendered',
],
)
await untilUpdated(() => page.textContent('#parent'), 'Updated')
})

In that case, allExportsAreComponentsOrUnchanged probably becomes true because of prevExports[key] === nextExports[key], and import.meta.hot.invalidate won't be called.

const allExportsAreComponentsOrUnchanged = predicateOnExport(


This PR fixes that flaky fail by waiting for the update to be processed.

@sapphi-red sapphi-red merged commit da18c65 into main Apr 16, 2025
10 checks passed
@sapphi-red sapphi-red deleted the test/react-hmr-wait-for-update branch April 16, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1-chore 🧹 Doesn't change code behavior (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants