Skip to content

Commit 725ae27

Browse files
committed
fix: Improve legacyRoot error message
1 parent 1645d21 commit 725ae27

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/__tests__/render.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe('render API', () => {
234234
expect(() => {
235235
render(<div />, {legacyRoot: true})
236236
}).toThrowErrorMatchingInlineSnapshot(
237-
`\`legacyRoot: true\` is not supported in this version of React. Please use React 18 instead.`,
237+
`\`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, and you need help with upgrading your app, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide.`,
238238
)
239239
})
240240

@@ -259,7 +259,7 @@ describe('render API', () => {
259259
expect(() => {
260260
render(ui, {container, hydrate: true, legacyRoot: true})
261261
}).toThrowErrorMatchingInlineSnapshot(
262-
`\`legacyRoot: true\` is not supported in this version of React. Please use React 18 instead.`,
262+
`\`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, and you need help with upgrading your app, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide.`,
263263
)
264264
})
265265
})

src/__tests__/renderHook.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ testGateReact19('legacyRoot throws', () => {
108108
},
109109
).result
110110
}).toThrowErrorMatchingInlineSnapshot(
111-
`\`legacyRoot: true\` is not supported in this version of React. Please use React 18 instead.`,
111+
`\`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, and you need help with upgrading your app, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide.`,
112112
)
113113
})

src/pure.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ function render(
209209
) {
210210
if (legacyRoot && typeof ReactDOM.render !== 'function') {
211211
const error = new Error(
212-
'`legacyRoot: true` is not supported in this version of React. Please use React 18 instead.',
212+
'`legacyRoot: true` is not supported in this version of React. ' +
213+
'If your app runs React 19 or later, you should remove this flag. ' +
214+
'If your app runs React 18 or earlier, and you need help with upgrading your app, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide.',
213215
)
214216
Error.captureStackTrace(error, render)
215217
throw error
@@ -274,7 +276,9 @@ function renderHook(renderCallback, options = {}) {
274276

275277
if (renderOptions.legacyRoot && typeof ReactDOM.render !== 'function') {
276278
const error = new Error(
277-
'`legacyRoot: true` is not supported in this version of React. Please use React 18 instead.',
279+
'`legacyRoot: true` is not supported in this version of React. ' +
280+
'If your app runs React 19 or later, you should remove this flag. ' +
281+
'If your app runs React 18 or earlier, and you need help with upgrading your app, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide.',
278282
)
279283
Error.captureStackTrace(error, renderHook)
280284
throw error

0 commit comments

Comments
 (0)