Skip to content

feat(ContentPreview): Noop for custom preview render prop#4458

Closed
ahorowitz123 wants to merge 2 commits intobox:masterfrom
ahorowitz123:noop_for_custom_preview_render_prop
Closed

feat(ContentPreview): Noop for custom preview render prop#4458
ahorowitz123 wants to merge 2 commits intobox:masterfrom
ahorowitz123:noop_for_custom_preview_render_prop

Conversation

@ahorowitz123
Copy link
Contributor

@ahorowitz123 ahorowitz123 commented Mar 2, 2026

Noop to release refactor(ContentPreview): change from children to render prop pattern

Summary by CodeRabbit

  • Breaking Changes

    • ContentPreview component now uses a renderCustomPreview prop for custom preview content instead of children. Users will need to update their implementation to pass a render function instead.
  • Tests

    • Updated test coverage to reflect the new custom preview API.

ahorowitz123 and others added 2 commits February 26, 2026 20:33
Refactors the custom preview API from children pattern to render prop
pattern for better ergonomics and clearer developer intent.

Changes:
- Replace children?: React.Node with renderCustomPreview
- Update CustomPreviewWrapper to call render function
- Wrap rendered content in fragment to satisfy ErrorBoundary
- Update all 119 tests to use render prop syntax
- Update JSDoc comments and examples

Before (children pattern):
  <ContentPreview fileId="123" token={token}>
    <MarkdownEditor />
  </ContentPreview>

After (render prop pattern):
  <ContentPreview
    fileId="123"
    token={token}
    renderCustomPreview={(props) => <MarkdownEditor {...props} />}
  />

Benefits:
- More explicit intent - function signature shows available props
- Better TypeScript/Flow type inference
- More idiomatic React pattern
- Easier conditional rendering and prop transformation

Testing:
- All 119 ContentPreview tests passing
- Flow: 0 errors
- ESLint: clean

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The onKeyDown handler was still checking the removed children prop, which meant
hotkey skipping never occurred for custom previews. Updated the conditional to
check renderCustomPreview instead, ensuring custom previews can implement their
own keyboard shortcuts without conflicts.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@ahorowitz123 ahorowitz123 requested review from a team as code owners March 2, 2026 17:27
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 881b71c and 18a6b58.

📒 Files selected for processing (3)
  • src/elements/content-preview/ContentPreview.js
  • src/elements/content-preview/CustomPreviewWrapper.js
  • src/elements/content-preview/__tests__/ContentPreview.test.js

Walkthrough

The PR replaces the children prop with a renderCustomPreview render-prop function for injecting custom preview content in the ContentPreview component. This API change is applied consistently across the core component, CustomPreviewWrapper, and all related tests.

Changes

Cohort / File(s) Summary
Core Custom Preview API
src/elements/content-preview/ContentPreview.js, src/elements/content-preview/CustomPreviewWrapper.js
Replaced children prop with renderCustomPreview: (props: ContentPreviewChildProps) => React.Node for custom preview content injection. Updated render logic, conditional checks, and prop passing to use the new render-prop pattern instead of React.cloneElement.
Test Updates
src/elements/content-preview/__tests__/ContentPreview.test.js
Updated all test cases to provide custom preview content via renderCustomPreview instead of children. Modified assertions, control flow paths, and wrapper expectations to reflect the new API surface and function-based content rendering.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • shahzadaziz
  • mickr

Poem

🐰 A render prop hops in with graceful design,
No cloned children cluttering the line,
Functions flow through with props so clean,
The sweetest preview API we've seen! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@ahorowitz123 ahorowitz123 deleted the noop_for_custom_preview_render_prop branch March 2, 2026 17:33
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