fix(docs): prevent custom components from being shadowed inside Aside (v2) #6148
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.
Fixes custom React components not rendering inside
<Aside>components.Short description of the changes made
When the
rehypeExtractAsidesplugin extracts Aside content, it generates a component that destructures JSX elements fromuseMDXComponents(). This was causing imported custom components to be shadowed byundefinedvalues, resulting in "Something went wrong!" errors.The fix extracts module-level ESM bindings from the full AST and filters them out from the list of components to destructure, preventing the shadowing of imported custom components.
What was the motivation & context behind this PR?
Custom React components (e.g.,
CustomCard) work correctly in the main content but fail inside<Aside>components. This was reported in Slack - see the test case at https://plantman-preview-4ed7e531-1b9f-402c-9f0f-a2e2b811e9ed.docs.buildwithfern.com/conceptsThe root cause: the generated
AsideComponentfunction createsconst { CustomCard } = MdxJsReact.useMDXComponents(), which shadows anyCustomCardimported at module scope. Since the MDXProvider doesn't haveCustomCard, it becomesundefined.How has this PR been tested?
pnpm lint:biome)Human review checklist:
extractJsx(ast).esmElementscorrectly captures imported component namesextractJsxcall should be moved after theasides.length === 0check for performanceLink to Devin run: https://app.devin.ai/sessions/48f55436d7304e6fbf43694fbaf910a7
Requested by: [email protected] (@Ryan-Amirthan)