feat: add defaultComponent fallback prop#548
Open
sleitor wants to merge 1 commit into
Open
Conversation
…ering Adds a new `defaultComponent` prop to `<Streamdown>`. When set, it acts as a fallback renderer for any HTML tag or allowed custom tag that does not have an explicit entry in the `components` map. - Applies to custom tags in `allowedTags` without an explicit component - Applies to HTML tags absent from the built-in Tailwind component set - Explicit `components` entries always take precedence - Backward-compatible: omitting the prop preserves existing behaviour - Uses a Proxy on the components map so hast-util-to-jsx-runtime's hasOwnProperty checks see the fallback for uncovered tag names Refs vercel#543
Contributor
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
defaultComponentprop to<Streamdown>— an additive, backwards-compatible fallback renderer for any HTML tag or allowed custom tag that does not have an explicit entry in thecomponentsmap.What it does
When
defaultComponentis set, it is used for:allowedTagsthat have no matching key incomponents<span>,<div>,<section>)Explicit
componentsentries always take precedence overdefaultComponent.Why
This directly addresses the boilerplate-reduction use case from Refs #543: users who want a pass-through/unstyled renderer no longer need to enumerate every tag individually.
Scope note
This PR implements only the
defaultComponentfallback — the clean, additive, backwards-compatible piece of Refs #543. The broaderStreamdown/StreamdownUnstyledsplit andclassName-merge semantic change described in the issue are architecture-level decisions that involve breaking changes and were intentionally left out of this PR.Implementation details
Proxyapproach is used on the components map so thathast-util-to-jsx-runtime'shasOwnPropertychecks (viaown.call) see the fallback for uncovered tag names — bothgetOwnPropertyDescriptorandgettraps are intercepted.allowedTagsentries are also eagerly registered in the map for clarity and correct Block-comparator invalidation.defaultComponentisundefined, behaviour is 100% unchanged (no Proxy created).Checklist
__tests__/default-component.test.tsx, 9 tests)pnpm check)Refs #543