Skip to content

fix(runtime): forward JSX key arg to controls that declare a key property - #4

Merged
petermuessig merged 2 commits into
mainfrom
fix/key-prop-forwarding
Sep 2, 2026
Merged

petermuessig merged 2 commits into
mainfrom
fix/key-prop-forwarding

Conversation

@petermuessig

@petermuessig petermuessig commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #3.

Babel's automatic JSX transform always extracts the key prop from element attributes and passes it as the third argument to jsx(type, props, key) — it is never inside the props object. Controls like sap.ui.core.CustomData declare a real key property (unrelated to React's reconciliation concept), so <CustomData key="testkey" .../> compiled to _jsx(CustomData, {...}, "testkey") and the key was silently dropped, producing the empty-key warning from UI5.

Changes

  • runtime.ts: After building propEntries, inject ["key", _key] when _key is defined and the control metadata declares a key property. The entry then travels through the normal intrinsic + applier pipeline (including propertyTypeIntrinsic validation) exactly like any other prop. For all controls without a key property the behaviour is unchanged.
  • jsx.qunit.ts: Two new tests — one verifying CustomData.key is set from the third arg, one confirming controls without a key property don't throw.
  • .changeset/fix-key-prop-forwarding.md: Patch-level changeset.
  • Showcase — Explore → Advanced → "CustomData & the key prop": Live sample (CustomDataKey.tsx) that attaches <CustomData key="product-id" value="4711" writeToDom={true} /> to a button and reads the resulting data-product-id attribute back in onAfterRendering() — giving an in-browser proof the fix is working end-to-end. Also removes the motivation for the new NavigationListItem({ key: "…" }) workaround noted in Explorer.controller.ts.

Test plan

  • pnpm --filter @ui5-community/jsx-runtime ts-typecheck passes
  • pnpm --filter @ui5-community/jsx-runtime-showcase ts-typecheck passes
  • pnpm --filter @ui5-community/jsx-runtime test-runner — new tests green, no regressions
  • Showcase: navigate to Explore → Advanced → CustomData & the key prop (#/explore/custom-data-key); readout shows DOM attribute: data-product-id="4711" and browser devtools confirm the attribute on the button's root element

…erty

Babel's automatic JSX transform always extracts the `key` prop from the
element's attributes and passes it as the third argument to jsx(type,
props, key). It is never present inside the props object. Controls like
sap.ui.core.CustomData own a real `key` property (distinct from React's
reconciliation key), so the value was silently dropped and the property
was never set.

The fix: after building propEntries from allProps, push ["key", _key]
when _key is defined and the control metadata declares a `key` property.
The entry travels through the normal intrinsic + applier pipeline
(including propertyTypeIntrinsic validation) exactly like any other prop.
For controls without a `key` property the behaviour is unchanged.

Fixes #3.
Adds a live showcase sample demonstrating the fix for issue #3:
`<CustomData key="product-id" value="4711" writeToDom={true} />` now
correctly forwards the JSX `key` attribute to `CustomData.setKey()`,
so UI5 writes the expected `data-product-id="4711"` DOM attribute.

The sample (Explore → Advanced → "CustomData & the key prop") renders
a button with an attached CustomData, reads the DOM attribute back in
`onAfterRendering()`, and displays it — giving a visible, in-browser
proof that the runtime fix is working end-to-end.

Four touchpoints:
- webapp/view/showcases/CustomDataKey.tsx  (live view)
- webapp/docs/samples/custom-data-key.md   (description markdown)
- webapp/view/ExploreSample.tsx            (REGISTRY entry)
- webapp/controller/Explorer.controller.ts (EXPLORE_GROUPS leaf)
@petermuessig
petermuessig merged commit ba7069d into main Sep 2, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 2, 2026
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.

property 'key' ignores by JSX runtime handler

1 participant