Skip to content

feat(astro): register a site's own MDX components - #30

Merged
CharanMN7 merged 1 commit into
mainfrom
feat/astro-site-components
Oct 27, 2026
Merged

CharanMN7 merged 1 commit into
mainfrom
feat/astro-site-components

Conversation

@CharanMN7

Copy link
Copy Markdown
Contributor

Adds a supported way for a site to register its own MDX components. The site that hit this, an Astro 7 site on @inkform/astro 0.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.

components option

inkform({ components: './src/mdx-components.tsx' });
  • Every export whose name starts with a capital letter can be used in any MDX page without an import. Entries of a default-exported object (export default { Screenshot }) work too.
  • They are merged over the kit's, so a site can add <Screenshot> or replace <Frame>. Unknown names still render the kit's visible fallback.
  • They render in the same build-time React pass as the kit. Image srcs and links they print get Astro's base, 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.
  • Exports that aren't components (helpers, constants) are ignored. A missing module fails the build at config time with its path.
  • Served through a virtual:@inkform/astro/components module, so Vite handles it like any other source file. Edits show up on reload in astro dev.

JSX without @astrojs/react

Astro's tsconfig preset sets "jsx": "preserve", and only a UI integration sets up JSX compilation. A .tsx components 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 set vite.oxc.jsx, the integration now sets Vite's oxc.jsx to React's automatic runtime. That only affects .jsx/.tsx files, which such a site can't use anywhere else. needsReactJsx() makes the decision and has unit tests.

Docs and example

  • README: the option in the table, plus a "Your own components" section covering wrapping kit components from @inkform/framework/components, overrides, the JSX note and the base-path behaviour.
  • examples/astro-docs registers src/mdx-components.tsx (<Screenshot>, styled through customCss). The components page uses it, and an e2e test checks it renders.
  • An Unreleased CHANGELOG entry is added. No version bump.

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, and needsReactJsx().
  • npm run typecheck for @inkform/astro and the example: 0 errors.
  • npm run test:e2e --workspace=@inkform/example-astro-docs: 36 pass.
  • A throwaway site with no @astrojs/react and a plain astro/tsconfigs/strict tsconfig, not committed, with base: '/ig' and trailingSlash: 'always'. Its .tsx module wraps the kit's Frame.
    • Before the JSX change, the build failed to parse the module. After it, astro build renders the component inside fw-frame.
    • astro dev serves it and picks up an edit to the module on the next request.
    • astro check reports 0 errors.

🤖 Generated with Claude Code

https://claude.ai/code/session_011YQ6fJxGHg3CxGkTzw6Yhc

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
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

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

2 Skipped Deployments
Project Deployment Actions Updated
framework-inkform-docs Skipped Skipped Oct 27, 2026 8:46am UTC
pokeapi Skipped Skipped Oct 27, 2026 8:46am UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – framework-inkform-docs October 27, 2026 08:46 Inactive
@vercel
vercel Bot temporarily deployed to Preview – pokeapi October 27, 2026 08:46 Inactive
@CharanMN7
CharanMN7 merged commit b7006b8 into main Oct 27, 2026
5 checks passed

This branch was previously deployed

2 inactive deployments
Preview – framework-inkform-docs — a2eb12e1 Deployed Oct 27, 2026 by vercel[bot]
Preview – pokeapi — a2eb12e1 Deployed Oct 27, 2026 by vercel[bot]
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