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

fix: Improve legacyRoot error message #1301

Merged
merged 2 commits into from Apr 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/__tests__/render.js
Expand Up @@ -234,7 +234,7 @@ describe('render API', () => {
expect(() => {
render(<div />, {legacyRoot: true})
}).toThrowErrorMatchingInlineSnapshot(
`\`legacyRoot: true\` is not supported in this version of React. Please use React 18 instead.`,
`\`legacyRoot: true\` is not supported in this version of React. If your app runs React 19 or later, you should remove this flag. If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.`,
)
})

Expand All @@ -259,7 +259,7 @@ describe('render API', () => {
expect(() => {
render(ui, {container, hydrate: true, legacyRoot: true})
}).toThrowErrorMatchingInlineSnapshot(
`\`legacyRoot: true\` is not supported in this version of React. Please use React 18 instead.`,
`\`legacyRoot: true\` is not supported in this version of React. If your app runs React 19 or later, you should remove this flag. If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.`,
)
})
})
2 changes: 1 addition & 1 deletion src/__tests__/renderHook.js
Expand Up @@ -108,6 +108,6 @@ testGateReact19('legacyRoot throws', () => {
},
).result
}).toThrowErrorMatchingInlineSnapshot(
`\`legacyRoot: true\` is not supported in this version of React. Please use React 18 instead.`,
`\`legacyRoot: true\` is not supported in this version of React. If your app runs React 19 or later, you should remove this flag. If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.`,
)
})
8 changes: 6 additions & 2 deletions src/pure.js
Expand Up @@ -209,7 +209,9 @@ function render(
) {
if (legacyRoot && typeof ReactDOM.render !== 'function') {
const error = new Error(
'`legacyRoot: true` is not supported in this version of React. Please use React 18 instead.',
'`legacyRoot: true` is not supported in this version of React. ' +
'If your app runs React 19 or later, you should remove this flag. ' +
'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.',
)
Error.captureStackTrace(error, render)
throw error
Expand Down Expand Up @@ -274,7 +276,9 @@ function renderHook(renderCallback, options = {}) {

if (renderOptions.legacyRoot && typeof ReactDOM.render !== 'function') {
const error = new Error(
'`legacyRoot: true` is not supported in this version of React. Please use React 18 instead.',
'`legacyRoot: true` is not supported in this version of React. ' +
'If your app runs React 19 or later, you should remove this flag. ' +
'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.',
)
Error.captureStackTrace(error, renderHook)
throw error
Expand Down