Repository navigation
feat(astro): register a site's own MDX components - #30
Merged
Merged
Conversation
A new `components` option points at a module of the site's own components. Every capitalized export (or entry of a default-exported object) works in MDX without imports, merged over the kit's, so a site can add a <Screenshot> or replace <Frame> instead of faking components with kit wrappers and CSS. They render through the same React pass as the kit, so links and images they print get Astro's base like the rest of the content. Astro's tsconfig preset leaves JSX uncompiled unless a UI integration sets it up, so when a site has none and the module is .jsx/.tsx, the integration has Vite compile its JSX for React. The example registers a <Screenshot> component with CSS through customCss, and an e2e test checks it renders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011YQ6fJxGHg3CxGkTzw6Yhc
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
This branch was previously deployed
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.
Adds a supported way for a site to register its own MDX components. The site that hit this, an Astro 7 site on
@inkform/astro0.1.0, faked a "screenshot slot" with the kit's<Frame>around a plain<div>plus CSS, because there was no way to add a component.componentsoptionexport default { Screenshot }) work too.<Screenshot>or replace<Frame>. Unknown names still render the kit's visible fallback.srcs and links they print get Astro'sbase, like the rest of the content (from fix(astro): Astro's base in every link, llms.txt trailing slashes, phone header #29). The docs pages still ship no React. The existing e2e test covers that.virtual:@inkform/astro/componentsmodule, so Vite handles it like any other source file. Edits show up on reload inastro dev.JSX without
@astrojs/reactAstro's tsconfig preset sets
"jsx": "preserve", and only a UI integration sets up JSX compilation. A.tsxcomponents module in a site without one failed with "JSX syntax is disabled". When the module is.jsx/.tsx, no React, Preact, Solid or Vue integration is installed, and the site hasn't setvite.oxc.jsx, the integration now sets Vite'soxc.jsxto React's automatic runtime. That only affects.jsx/.tsxfiles, which such a site can't use anywhere else.needsReactJsx()makes the decision and has unit tests.Docs and example
@inkform/framework/components, overrides, the JSX note and the base-path behaviour.examples/astro-docsregisterssrc/mdx-components.tsx(<Screenshot>, styled throughcustomCss). The components page uses it, and an e2e test checks it renders.Test plan
npm test --workspace=@inkform/astro: 72 pass. New tests cover option resolution, the virtual module source,userComponents()(memo/forwardRef, default object, ignoring non-components), rendering with a kit override and the fallback kept, andneedsReactJsx().npm run typecheckfor@inkform/astroand the example: 0 errors.npm run test:e2e --workspace=@inkform/example-astro-docs: 36 pass.@astrojs/reactand a plainastro/tsconfigs/stricttsconfig, not committed, withbase: '/ig'andtrailingSlash: 'always'. Its.tsxmodule wraps the kit'sFrame.astro buildrenders the component insidefw-frame.astro devserves it and picks up an edit to the module on the next request.astro checkreports 0 errors.🤖 Generated with Claude Code
https://claude.ai/code/session_011YQ6fJxGHg3CxGkTzw6Yhc