Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDX support #3706

Merged
merged 52 commits into from
Jun 30, 2022
Merged

MDX support #3706

merged 52 commits into from
Jun 30, 2022

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Jun 24, 2022

Changes

  • Adds @astrojs/mdx integration
  • Adds support for top-level .mdx pages

Testing

  • Basic unit tests added to integration package
  • .mdx file added to each framework e2e test

Docs

  • README has new integration template
  • New with-mdx example includes README
  • Probably more docs to be added, but good for now?

@changeset-bot
Copy link

changeset-bot bot commented Jun 24, 2022

🦋 Changeset detected

Latest commit: bfb72ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
astro Patch
@astrojs/mdx Patch
@e2e/astro-component Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) pkg: preact Related to Preact (scope) pkg: integration Related to any renderer integration (scope) labels Jun 24, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2022

⚖️ Bundle Size Check

Latest commit: efdd022

File Old Size New Size Change
hmr 5.31 KB 5.38 KB + 70 B

@natemoo-re natemoo-re force-pushed the feat/mdx branch 2 times, most recently from 55c45df to de0a31a Compare June 28, 2022 16:35
@natemoo-re natemoo-re marked this pull request as ready for review June 29, 2022 20:04
@github-actions github-actions bot removed the pkg: preact Related to Preact (scope) label Jun 29, 2022
Comment on lines +169 to +171
const rendererAliases = new Map([
['solid', 'solid-js']
])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated bug caught by update to e2e tests. We should support both client:only="solid" and client:only="solid-js"

Comment on lines +181 to +183
if (!importSource && jsxRenderers.has('astro') && id.includes('.mdx')) {
importSource = 'astro';
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only default to astro/jsx-runtime if it's an .mdx component

Comment on lines +942 to +944
export type HookParameters<Hook extends keyof AstroIntegration['hooks'], Fn = AstroIntegration['hooks'][Hook]> = Fn extends (...args: any) => any
? Parameters<Fn>[0]
: never;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small QoL thing but this exposes a type for Integration hook parameters

packages/astro/src/core/create-vite.ts Show resolved Hide resolved
Comment on lines 143 to 149
if (!Component.isAstroComponentFactory) {
const props: Record<string, any> = { ...(pageProps ?? {}), 'server:root': true };
const html = await renderComponent(result, Component.name, Component, props, null);
return new Response(html.toString(), result.response);
} else {
return await renderPage(result, Component, pageProps, null);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this logic into renderPage

packages/astro/src/runtime/server/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDX in Astro, who knew! A few small questions/comments but this is excellent 🚀

packages/astro/src/core/create-vite.ts Show resolved Hide resolved
packages/astro/src/core/render/core.ts Show resolved Hide resolved
packages/astro/src/runtime/server/index.ts Outdated Show resolved Hide resolved
packages/integrations/mdx/test/mdx-component.test.js Outdated Show resolved Hide resolved
packages/integrations/mdx/test/mdx-page.test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed to @tony-sull's comment on testing as well. Mostly nits, but super mdxcited to get this merged!

packages/astro/src/core/create-vite.ts Show resolved Hide resolved
packages/astro/src/core/render/dev/index.ts Outdated Show resolved Hide resolved
packages/astro/src/runtime/client/hmr.ts Outdated Show resolved Hide resolved
packages/astro/src/runtime/server/index.ts Outdated Show resolved Hide resolved
packages/integrations/mdx/README.md Show resolved Hide resolved
packages/integrations/mdx/src/index.ts Show resolved Hide resolved
packages/integrations/mdx/src/index.ts Show resolved Hide resolved
Copy link
Contributor

@hippotastic hippotastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall! Just found a tiny nit, nothing else so far. Great work!

packages/integrations/mdx/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Just needs a changeset then ship it 🚀

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge Dat Xperience!

packages/astro/src/core/util.ts Show resolved Hide resolved
@natemoo-re natemoo-re merged commit 032ad1c into main Jun 30, 2022
@natemoo-re natemoo-re deleted the feat/mdx branch June 30, 2022 18:09
@astrobot-houston astrobot-houston mentioned this pull request Jun 30, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* feat: first pass at MDX support

* fix: move built-in JSX renderer to come first

* chore: remove jsx example

* chore: update lockfile

* chore: cleanup example

* fix: missing deps

* refactor: move component render logic to `renderPage`

* chore: update HMR script

* chore: update MDX example

* refactor: prefer unshit

* refactor: remove TODO comment

* fix: remove duplicate identifier

* refactor: cleanup mdx entrypoint

* fix: better html handling

* fix: add tsconfig to mdx package

* chore: update lockfile

* fix: do not sort plugins unless mdx is enabled

* chore: update compiler

* fix(hmr): maybe render head for non-Astro pages

* fix: set initial pageExtensions

* refactor: cleanup addPageExtension

* refactor: remove addPageExtensions from types

* refactor: expose HookParameters type

* fix: only default to astro for MDX

* test: pick up jsx support in test fixtures

* refactor: simplify mdx entrypoint

* test: add basic MDX tests

* test(e2e): add mdx + framework tests

* chore: update lockfile

* test(e2e): fix preact mdx e2e test

* fix(mdx): disable .md support

* test(e2e): fix vue-component test missing mdx

* test(e2e): fix solid component needing import

* fix: allow `client:only="solid"` as an alias to `solid-js`

* chore: move to with-mdx example

* chore: update MDX readme

* chore: update example readme

* chore: bump astro version

* chore: update lockfile

* Update mod.d.ts

* feat: support `export const components` in MDX pages

* chore: update mdx example

* fix: update jsx-runtime with better slot support

* refactor: remove object style support

* chore: cleanup package exports

* chore: add todo comment

* refactor: improve isPage function, move to utils

* refactor: dry up manual HMR updates

* chore: add dev tests for MDX

* chore: prefer set to array

* chore: add changesets

* fix(hmr): flip public/private route

Co-authored-by: Nate Moore <nate@astro.build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants