Skip to content

refactor: replace as prop with render prop in Text and Headline#740

Merged
rohanchkrabrty merged 3 commits into
mainfrom
644-text-headline-render-prop
Apr 17, 2026
Merged

refactor: replace as prop with render prop in Text and Headline#740
rohanchkrabrty merged 3 commits into
mainfrom
644-text-headline-render-prop

Conversation

@rohanchkrabrty

Copy link
Copy Markdown
Contributor

Summary

  • Replace the as polymorphic prop with Base UI's render prop + useRender hook in the Text and Headline components, matching the existing pattern used by the Flex component.
  • Remove brittle per-element type unions (TextSpanProps, TextDivProps, etc.) and the @ts-expect-error suppression, using useRender.ComponentProps<'span'> / useRender.ComponentProps<'h2'> instead.
  • Update the Link component (which used as='a' on Text) to use render={<a />}.
  • Update all tests, docs, playground controls, and example files to use the render prop.

Test plan

  • All Text tests pass (89 tests including 7 new render prop tests)
  • All Headline tests pass (33 tests including 7 new render prop tests)
  • All Link tests pass (12 tests)
  • TypeScript compiles cleanly for text, headline, and link components (npx tsc --noEmit)
  • Verify default tag rendering (<span> for Text, <h2> for Headline)
  • Verify render prop with JSX element (e.g., <Text render={<h1 />}>)
  • Verify render function (e.g., <Text render={(props) => <section {...props} />}>)

🤖 Generated with Claude Code

@vercel

vercel Bot commented Apr 14, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Apr 17, 2026 6:54am

@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@rohanchkrabrty has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 59 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 51 minutes and 59 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 49725e1f-86e6-4d73-92e5-9ffc64047cdc

📥 Commits

Reviewing files that changed from the base of the PR and between 3812aa4 and 81f9d6f.

📒 Files selected for processing (13)
  • apps/www/src/components/playground/headline-examples.tsx
  • apps/www/src/content/docs/components/headline/demo.ts
  • apps/www/src/content/docs/components/headline/index.mdx
  • apps/www/src/content/docs/components/headline/props.ts
  • apps/www/src/content/docs/components/text/demo.ts
  • apps/www/src/content/docs/components/text/index.mdx
  • apps/www/src/content/docs/components/text/props.ts
  • docs/V1-migration.md
  • packages/raystack/components/headline/__tests__/headline.test.tsx
  • packages/raystack/components/headline/headline.tsx
  • packages/raystack/components/link/link.tsx
  • packages/raystack/components/text/__tests__/text.test.tsx
  • packages/raystack/components/text/text.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

rohanchkrabrty and others added 3 commits April 17, 2026 12:18
Migrate Text and Headline components from the brittle `as` polymorphic
prop pattern to Base UI's `render` prop + `useRender` hook, matching
the pattern already used by the Flex component. This eliminates manual
type unions, removes a `@ts-expect-error` suppression, and enables
rendering as any element via JSX or render functions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The render prop accepts ReactElement values, not strings. Update
playground select options to use JSX element strings (e.g. '<h2 />')
so getPropsString generates correct `render={<h2 />}` syntax.
Also document the render prop in Headline's API Reference section.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add migration documentation for the breaking change where `as` prop is
replaced by `render` on Text and Headline components. Includes
before/after examples, TypeScript type change notes, and render function
usage. Updates Table of Contents, cross-cutting changes note, and
Migration Checklist.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
expect(heading.tagName).toBe('H2');
});

it('supports render function', () => {

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.

This test is redundant as renders as h1 via render prop is exactly the same.

@rohanchkrabrty rohanchkrabrty merged commit 4ccb30c into main Apr 17, 2026
5 checks passed
@rohanchkrabrty rohanchkrabrty deleted the 644-text-headline-render-prop branch April 17, 2026 08:11
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.

3 participants