dillon1000/react

Commit

Warn if outdated JSX transform is detected (#28781)

We want to warn if we detect that an app is using an outdated JSX
transform. We can't just warn if `createElement` is called because we
still support `createElement` when it's called manually. We only want to
warn if `createElement` is output by the compiler.

The heuristic is to check for a `__self` prop, which is an optional,
internal prop that older transforms used to pass to `createElement` for
better debugging in development mode.

If `__self` is present, we `console.warn` once with advice to upgrade to
the modern JSX transform. Subsequent elements will not warn.

There's a special case we have to account for: when a static "key" prop
is defined _after_ a spread, the modern JSX transform outputs
`createElement` instead of `jsx`. (This is because with `jsx`, a spread
key always takes precedence over a static key, regardless of the order,
whereas `createElement` respects the order.) To avoid a false positive
warning, we skip the warning whenever a `key` prop is present.
Browse files
Changed paths3 files
First-parent comparison
M packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.js ModifiedM packages/react/src/__tests__/ReactCreateElement-test.js ModifiedM packages/react/src/jsx/ReactJSXElement.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…