Skip to content

feat(render)!: add useRender, apply render to components and remove asChild - #1017

Draft
gamegee wants to merge 3 commits into
mainfrom
feat/use-render
Draft

gamegee wants to merge 3 commits into
mainfrom
feat/use-render

Conversation

@gamegee

@gamegee gamegee commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Context

First step to deprecate the Radix asChild pattern in favor of a Base UI–style render prop, on web and React Native alike. Today Lumen mixes both: Popover, Menu and Select triggers take render, while Button, Link, Dialog and Tooltip take asChild. A consumer scan of 17 production repos found about 412 call sites that would use render: existing asChild, navigation in click handlers, and hand-built link wrappers.

This PR only adds the abstraction. No component adopts it yet; that comes in a follow-up PR.

Technical details

  • utils-shared:
    • RenderProp<Props, State> and WithRenderProp are the shared, platform-neutral types.
    • asChildToRender maps asChild + child onto render + children. It lets the next PR keep asChild working as a deprecated alias.
  • ui-react:
    • Internal useRender hook, a thin wrapper over @base-ui/react/use-render.
    • The one addition: the render element's className goes through cn (tailwind-merge), so a consumer class overrides a conflicting Lumen utility instead of being concatenated.
  • ui-rnative:
    • Internal useRender hook with the same contract: element or (props, state) => element, chained handlers, combined styles (including Pressable style functions), merged refs. Default component is Pressable.
    • The Slot's mergeProps/combineStyles moved to lib/utils/mergeProps, because the layer rules forbid utils importing from Components/. Slot.tsx now imports it, with no behavior change.
  • Public API: only the types (RenderProp, WithRenderProp) are exported from ui-react and ui-rnative. The hooks stay internal.
  • Usage convention: a component calls the hook in place of its root JSX, e.g. return useRender({ defaultTagName: 'button', render, ref, state, props }). No wrapper component.

Start reviewing at libs/ui-react/src/utils/useRender/useRender.ts and libs/ui-rnative/src/lib/utils/useRender/useRender.tsx.

How to test

CI covers it. Locally, run npx nx run-many -t lint typecheck test --projects=@ledgerhq/lumen-utils-shared,@ledgerhq/lumen-ui-react,@ledgerhq/lumen-ui-rnative and npm run check:layers.

Follow-ups

  • Next PR: adopt render in BaseButton (Button, IconButton, MediaButton, TileButton), Link and ListItem, and deprecate asChild through asChildToRender.
  • Document the render convention in the component-architecture skill.

Update: render applied, asChild removed

This PR now also applies render to every component that scored 2+ in the consumer study, and removes asChild entirely (breaking, covered by the as-child-to-render migration).

  • Web: Button, IconButton, MediaButton, TileButton (via BaseButton), Link, DialogTrigger, DialogClose, TooltipTrigger, ListItem, Card, CardButton, Tile, MediaCard, SideBarItem, NavBarBackButton, MenuItem (forwards Base UI's render). DialogContent.asChild is removed with no replacement.
  • Dialog / Tooltip triggers keep Radix for now: useRender builds the element and Radix's trigger merges onto it with an internal asChild. Moving those primitives to Base UI is a separate change.
  • React Native: the same set where it exists. TooltipTrigger and BaseCheckbox lose asChild, and the internal Slot is deleted (mergeProps stays).
  • Peers: @radix-ui/react-slot is no longer a peer of ui-react.
  • utils-shared: keeps only the RenderProp / WithRenderProp types. The asChildToRender bridge is gone.
  • Behavior: with render, Lumen components keep their own content (icon, spinner, label, the Link external icon plus target/rel). Triggers take the whole element, as MenuTrigger already does: render={<Button>Open</Button>}.

…d React Native

First step to replace asChild with a render prop. Adds shared RenderProp
types and an asChildToRender bridge in utils-shared, an internal useRender
hook in ui-react (wrapping Base UI, with tailwind-merge on the render
element className) and in ui-rnative (on the Slot merge logic, moved to
utils). No component adopts it yet.
@gamegee
gamegee requested a review from a team as a code owner November 30, 2026 10:56
Copilot AI balanced review requested due to automatic review settings November 30, 2026 10:56
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ldls Ready Ready Preview Nov 30, 2026 4:39pm UTC
ldls-react-native Ready Ready Preview Nov 30, 2026 4:39pm UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The replacement’s children overwrite component-generated children, discarding wrappers or composed content and violating the outer-element-only contract.

1 open issue
What changed in this PR

This PR lays the foundation for a consistent render prop across Lumen’s web and React Native components. It adds internal hooks and public types without migrating any components yet.

Changes:

  • Add shared render-prop types and an asChildToRender compatibility bridge.
  • Introduce platform-specific hooks for composing replacement elements, props, styles, handlers, and refs.
  • Extract native Slot’s merge utility and add tests, exports, and patch version plans.
File Description
libs/​utils-shared/​src/​lib/​renderProp/​renderProp.ts Define shared types and the compatibility bridge.
libs/​utils-shared/​src/​lib/​renderProp/​renderProp.test.tsx Test bridge conversion and precedence.
libs/​utils-shared/​src/​lib/​renderProp/​index.ts Export shared render-prop utilities.
libs/​utils-shared/​src/​index.ts Expose utilities through the package root.
libs/​ui-rnative/​src/​lib/​utils/​useRender/​useRender.tsx Add the internal native rendering hook.
libs/​ui-rnative/​src/​lib/​utils/​useRender/​useRender.test.tsx Test native rendering, styles, handlers, and refs.
libs/​ui-rnative/​src/​lib/​utils/​useRender/​types.ts Define native hook and render-prop types.
libs/​ui-rnative/​src/​lib/​utils/​useRender/​index.ts Collect internal hook exports.
libs/​ui-rnative/​src/​lib/​utils/​mergeProps/​mergeProps.ts Extract native prop and style merging.
libs/​ui-rnative/​src/​lib/​utils/​mergeProps/​mergeProps.test.ts Test merge precedence, handlers, and styles.
libs/​ui-rnative/​src/​lib/​utils/​mergeProps/​index.ts Export the merge utility internally.
libs/​ui-rnative/​src/​lib/​Components/​internal/​Slot/​Slot.tsx Reuse the extracted utility without changing behavior.
libs/​ui-rnative/​src/​index.ts Publicly export native render-prop types.
libs/​ui-react/​src/​utils/​useRender/​useRender.ts Wrap Base UI rendering with Tailwind class merging.
libs/​ui-react/​src/​utils/​useRender/​useRender.test.tsx Test web rendering, classes, state, handlers, and refs.
libs/​ui-react/​src/​utils/​useRender/​types.ts Define web hook and render-prop types.
libs/​ui-react/​src/​utils/​useRender/​index.ts Collect internal hook exports.
libs/​ui-react/​src/​index.ts Publicly export web render-prop types.
.nx/​version-plans/​version-plan-1796035811002-ui-rnative.md Schedule the native package patch release.
.nx/​version-plans/​version-plan-1796035811001-ui-react.md Schedule the web package patch release.
.nx/​version-plans/​version-plan-1796035811000-utils-shared.md Schedule the shared utilities patch release.

Review effort: Balanced


if (isValidElement<Record<string, unknown>>(render)) {
return cloneElement(render, {
...mergeProps(ownProps, render.props),
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Lumen PR report

Test coverage

Libs must reach 80% on every metric. Δ is against the latest green main; italic rows did not run in this PR and show main's numbers.

Lib Lines Statements Functions Branches Gate
design-core 99.50% 99.51% 100.00% 90.90% not run
lint-plugin 97.10% 96.00% 100.00% 93.75% not run
migrations 96.44% (±0) 95.13% (±0) 100.00% (±0) 89.21% (±0) ✅
symbols — — — — not run
ui-react 96.58% (+0.01) 95.96% (+0.02) 94.82% (+0.01) 92.17% (−0.03) ✅
ui-rnative 95.76% (+1.57) 95.49% (+1.51) 94.95% (+1.44) 88.53% (+2.11) ✅
utils-shared 98.94% (±0) 99.02% (±0) 99.24% (±0) 94.22% (±0) ✅
Internals (reported, not gated)
Project Lines Statements Functions Branches
adoption-tool 78.33% 78.10% 84.43% 84.73%
design-build 88.30% 87.63% 92.85% 77.17%
design-sources 90.10% 88.63% 89.61% 85.94%
repo-tools 39.26% 39.22% 70.74% 41.53%
sync-figma 81.35% 81.76% 79.10% 88.39%

@gamegee
gamegee marked this pull request as draft November 30, 2026 15:09
@gamegee gamegee added the publish-dev-package Publishes affected packages to the JFrog sandbox registry on each commit label Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Dev packages published

Tarballs are hosted as assets on a per-PR GitHub pre-release and are deleted automatically when this PR is closed.

Package Version Install
@ledgerhq/lumen-migrations 0.0.5-pr.1017.4303c28 npm i https://github.com/LedgerHQ/lumen/releases/download/dev-pr-1017/ledgerhq-lumen-migrations-0.0.5-pr.1017.4303c28.tgz
@ledgerhq/lumen-ui-react 0.1.76-pr.1017.4303c28 npm i https://github.com/LedgerHQ/lumen/releases/download/dev-pr-1017/ledgerhq-lumen-ui-react-0.1.76-pr.1017.4303c28.tgz
@ledgerhq/lumen-ui-rnative 0.1.77-pr.1017.4303c28 npm i https://github.com/LedgerHQ/lumen/releases/download/dev-pr-1017/ledgerhq-lumen-ui-rnative-0.1.77-pr.1017.4303c28.tgz
@ledgerhq/lumen-utils-shared 0.1.20-pr.1017.4303c28 npm i https://github.com/LedgerHQ/lumen/releases/download/dev-pr-1017/ledgerhq-lumen-utils-shared-0.1.20-pr.1017.4303c28.tgz

Release: dev-pr-1017
Commit: 4303c289eecf93f371c18a7b88fef797e32a27c1

Web: Button family, Link, Dialog/Tooltip triggers, ListItem, Card, CardButton,
Tile, MediaCard, SideBarItem, NavBarBackButton, MenuItem. React Native: the
same set where it exists. Drops the @radix-ui/react-slot peer and the RN Slot,
and adds the as-child-to-render migration.
@gamegee gamegee changed the title feat(useRender): add render-prop hook and RenderProp types for web and React Native feat(render)!: add useRender, apply render to components and remove asChild Nov 30, 2026
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch was successfully deployed

2 active deployments
Preview – ldls — 4303c289 Deployed Nov 30, 2026 by vercel[bot]
Preview – ldls-react-native — 4303c289 Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

publish-dev-package Publishes affected packages to the JFrog sandbox registry on each commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants