-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: add server islands support for MDX
#12574
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
feat: add server islands support for MDX
#12574
Conversation
🦋 Changeset detectedLatest commit: 41e55b2 The changes in this PR will be included in the next version bump. 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 |
MDX
CodSpeed Performance ReportMerging #12574 will not alter performanceComparing Summary
|
|
@apatel369 any updates? |
|
@ematipico I applied the changes suggested by @matthewp. Tests are still failing. |
|
@apatel369 the PR was in draft for a long time without any updates. What suggestions are you referring to? What kind of help do you need? |
| } | ||
| }, | ||
| transform(_code, id) { | ||
| if (id.endsWith('.astro')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was preventing retrieving server islands data from mdx files metadata
| props[key] = value; | ||
| } | ||
| } | ||
| const str = await renderToString(result, vnode.type as any, props, slots); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was calling the component factory as is. Instead, we want it to go through renderAstroComponent so the server island special handling can take effect
| ...meta, | ||
| astro: { | ||
| ...(meta.astro ?? { hydratedComponents: [], clientOnlyComponents: [], scripts: [] }), | ||
| ...(meta.astro ?? createDefaultAstroMetadata()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the server island plugin is running for all files, this was failing because the metadata was not initialized with serverComponents: []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming that no docs update is needed:
- there's nothing in docs that explicitly says this wasn't possible before, or that server islands could only be rendered in
.astrocomponents - all current wording re: MDX refers to the ability to "use Astro components", which server islands are.
| logger.error( | ||
| 'islands', | ||
| 'You tried to render a server island without an adapter added to your project. An adapter is required to use the `server:defer` attribute on any component. Your project will fail to build unless you add an adapter or remove the attribute.', | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| logger.error( | |
| 'islands', | |
| 'You tried to render a server island without an adapter added to your project. An adapter is required to use the `server:defer` attribute on any component. Your project will fail to build unless you add an adapter or remove the attribute.', | |
| ); | |
| logger.error( | |
| 'islands', | |
| 'You tried to render a server island without an adapter added to your project. An adapter is required to use the `server:defer` attribute on any component. Your project will fail to build unless you add an adapter or remove the attribute.', | |
| ); | |
| continue; |
We should not process the island, I think. Make sure to print the name of the component, so the users know which component island is failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should stop the processing. We have this in a few places IIRC where we only warn if stuff is going to break if no adapter is added, and only break during build. I think that applies here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Co-authored-by: Matthew Phillips <[email protected]> Co-authored-by: Emanuele Stoppa <[email protected]> Co-authored-by: Florian Lefebvre <[email protected]>
Changes
.mdxfiles #12252Testing
Manual and new fixture test
Docs
Changeset