fix: stop reading key from element props on React 19 - #97
Open
d-mato wants to merge 1 commit into
Open
Conversation
d-mato
force-pushed
the
fix/key-prop-warning
branch
from
August 20, 2026 12:48
adc8d7a to
e3a9ca9
Compare
d-mato
marked this pull request as ready for review
August 20, 2026 12:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the
%s: `key` is not a prop.console error React logs when<Hyperlink />processes an element that carries akey, as reported in #88.Problem
In development React defines
keyon an element's props as a non-enumerable warning getter, and freezes those props. Destructuring reads it and triggers the warning; a spread does not, because the getter is non-enumerable.render(),linkify()andparse()all destructurekeyout of props, so any keyed element rendered inside<Hyperlink />triggers it. React logs the warning only once per process, so it can look absent when another code path happens to readkeyfirst.Solution
Copy the props instead of destructuring them:
A spread copies own enumerable properties only, so neither the
keygetter nor therefgetter React 18 defines the same way is read.ref- a regular prop since React 19 - is deleted from the copy rather than from the frozen original, so the fix forProperty 'ref'/'key' is not configurable(#85, #88) stays intact.keyis never an own enumerable prop, so the destructuring always readundefined: the resulting props are identical and behaviour is unchanged.Changes
propsWithoutRefhelper, used inrender(),linkify()andparse()src/__tests__/special-props.test.tsxTesting
masteryarn test,yarn typecheck,yarn lint,yarn prepareFixes
Refs #88