-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
Add support for SSR #1255
Add support for SSR #1255
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
🦋 Changeset detectedLatest commit: fac8782 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Hello! Thank you for opening your first PR to Starlight! ✨ Here’s what will happen next:
|
For anyone that want to try this out on their website to check for problems you can install it with:
|
Probably blocked by withastro/astro#9392, due to that bug any project using Starlight with SSR cannot add any other page to the project as everything will be overridden by Starlight's |
Any updates on that? I have to patch package to add |
This depended on withastro/astro#9439, released on 4.2. It's on my pipe to come back to this and make any necessary changes. I'll probably ping people to review it by next Tuesday. |
waiting for this to be released 🙏 |
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.
Thanks for taking my suggestions on board @Fryuni! This is in great shape. Left a last couple of comments on the files I didn’t get to yesterday.
@@ -72,6 +73,13 @@ export async function runPlugins( | |||
}); | |||
} | |||
|
|||
if (context.config.output === 'static' && !starlightConfig.prerender) { |
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 guess we’ll need to revisit this for Astro v5 given withastro/astro#11824 — probably something like checking there’s an adapter
? (No action needed, just sharing the observation to up our chances of one of us remembering 😁)
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 PR is almost the entirety of v4. It started two days after 4.0.0 and now we have to consider how v5 just around the corner will break it 😅
[skip ci] Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
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.
Thanks for the last updates @Fryuni! Looks good to me! 🎊
I think one thing we can think about for the future is if this needs any more documentation (the current SSR section is a bit hidden in the manual setup guide), but I’m happy to run with this as it’s a rarer option for people.
Will take a look to see if there are other things we’d like to get released with this and decide when to cut the next minor.
Updated the end-to-end fixtures to the latest Astro release to match the updates in #2287 — tests still all seem good! |
Just wanted to say I'm excited! 🥳 Congrats, @Fryuni ! |
Hey, folks! I just wanted to let you know that I've been following this PR for the last couple of months and wanted to congrats everyone involved on this effort. You did an amazing job here @Fryuni @HiDeoo and @delucis! I'm saving this PR as an example of open source contribution. Really cool to see these in-depth discussions happening async, and moving forward! Again, congrats and thank you @Fryuni ! |
Trabalho incrível, @Fryuni! Congrats team! |
🎉 |
* main: (37 commits) [ci] format i18n(ko-KR): update `manual-setup.mdx` (withastro#2294) i18n(ko-KR): update `configuration.mdx` (withastro#2295) [ci] release (withastro#2292) Add support for SSR (withastro#1255) Add Markdoc preset and example (withastro#2249) Refactor sidebar persistence logic for better slow device performance (withastro#2242) [ci] format Add docs.ryzekit.com to showcase (withastro#2291) Update astro dependency to 4.15.3 across monorepo (withastro#2289) [ci] release (withastro#2290) Prevent Zod errors from crashing build (withastro#2288) i18n(fr): update `guides/css-and-tailwind` (withastro#2286) i18n(ko-KR): update `css-and-tailwind.mdx` (withastro#2284) Add WCAG AAA colour contrast option to theme editor (withastro#2282) [ci] release (withastro#2283) Parse `<StarlightPage />` frontmatter asynchronously (withastro#2279) Ensure unhandled directives are restored without any extra whitespace (withastro#2281) i18n(fr): update `resources/plugins` (withastro#2278) i18n(ko-KR): update `plugins.mdx` (withastro#2277) ...
* main: (22 commits) i18n(ru): update `ru/manual-setup.mdx` and `ru/reference/configuration.mdx` (withastro#2307) [ci] format i18n(ru): update some guides (withastro#2306) i18n(fr): update `manual-setup` (withastro#2299) i18n(fr): update `guides/pages` (withastro#2298) [ci] release (withastro#2304) Convert URL to file path correctly for Git virtual module (withastro#2303) i18n(fr): update `reference/configuration` (withastro#2296) i18n(fr): update `guides/authoring-content` (withastro#2297) Update `yummacss.com.png` thumbnail (withastro#2301) i18n(ko-KR): update `pages.mdx` (withastro#2293) [ci] format i18n(ko-KR): update `authoring-content.mdx` (withastro#2300) [ci] format i18n(ko-KR): update `manual-setup.mdx` (withastro#2294) i18n(ko-KR): update `configuration.mdx` (withastro#2295) [ci] release (withastro#2292) Add support for SSR (withastro#1255) Add Markdoc preset and example (withastro#2249) Refactor sidebar persistence logic for better slow device performance (withastro#2242) ...
Summary
Add configuration for not prerendering Starlight pages.
This enables using components with SSR logic on Starlight pages, whether in the content or as component overrides.
Notes
Double index
To do this without triggering multiple warnings, there are now two
.astro
pages for the index entrypoint:index.astro
is always prerendered and usesgetStaticPaths
andAstro.props
to receive information about the route.indexSSR.astro
that is never prerendered and retrieves the information about the route from the dynamic route parameter.Route parameter indexing
To make the SSR rendering efficient, a lookup map for all the content was created using the parameter that will be received from the dynamic route.
Pagefind
Pagefind indexing requires access to the HTML file generated by the routes, but those are not available when building for SSR, so Pagefind is not supported when using SSR.
The solution that I implemented for this is that when both SSR and Pagefind are enabled for Starlight, the content of the docs is pre-rendered for indexing but not included in the final build. The final content served will be from SSR, but the index will be built from that static rendering.Default behavior
Starlight will default to the same as any other Astro page, prerendering when the output mode is not defined, when it isstatic
, and when it ishybrid
. When the output mode isserver
, Starlight will default to SSR.Starlight previously didn't build at all when the site had output mode set toserver
, so the different default is not, AFAICT, a breaking change.Starlight will default to prerender pages, which differs from the default for Astro pages. This is to maintain compatibility and because docs pages are most commonly not dynamic. Users must set
prerender: false
in their Starlight configuration to enable on-demand docs page rendering. At the moment, this applies to all Starlight pages. Future work could be done to support SSR on only some of the pages.TODO
child_process
logic to build plugins (git information)