Skip to content

fix: stop reading key from element props on React 19 - #97

Open
d-mato wants to merge 1 commit into
obipawan:masterfrom
d-mato:fix/key-prop-warning
Open

fix: stop reading key from element props on React 19#97
d-mato wants to merge 1 commit into
obipawan:masterfrom
d-mato:fix/key-prop-warning

Conversation

@d-mato

@d-mato d-mato commented Aug 20, 2026

Copy link
Copy Markdown

Description

Fixes the %s: `key` is not a prop. console error React logs when <Hyperlink /> processes an element that carries a key, as reported in #88.

Problem

In development React defines key on 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() and parse() all destructure key out 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 read key first.

Solution

Copy the props instead of destructuring them:

const propsWithoutRef = <T extends object>(props: T): T => {
	const rest: T & { ref?: unknown } = { ...props };
	delete rest.ref;
	return rest;
};

A spread copies own enumerable properties only, so neither the key getter nor the ref getter 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 for Property 'ref'/'key' is not configurable (#85, #88) stays intact.

key is never an own enumerable prop, so the destructuring always read undefined: the resulting props are identical and behaviour is unchanged.

Changes

  • Added a propsWithoutRef helper, used in render(), linkify() and parse()
  • Added src/__tests__/special-props.test.tsx

Testing

  • ✅ New unit tests covering the three paths above, which fail on master
  • yarn test, yarn typecheck, yarn lint, yarn prepare
  • ✅ No breaking changes to existing API

Fixes

Refs #88

@d-mato
d-mato force-pushed the fix/key-prop-warning branch from adc8d7a to e3a9ca9 Compare August 20, 2026 12:48
@d-mato
d-mato marked this pull request as ready for review August 20, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant