fix(astro): use prerender loader environment for metadata#16618
Open
bittoby wants to merge 1 commit intowithastro:mainfrom
Open
fix(astro): use prerender loader environment for metadata#16618bittoby wants to merge 1 commit intowithastro:mainfrom
bittoby wants to merge 1 commit intowithastro:mainfrom
Conversation
🦋 Changeset detectedLatest commit: c83c987 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 |
Contributor
Author
|
Hi @ematipico @matthewp, could you please take a look at my small PR? Welcome to any feedback |
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.
Changes
ModuleLoader.getSSREnvironment()to return thessrEnvironmentparameter the loader was constructed with, instead of always looking upviteServer.environments.ssr.prerenderVite dev environment (notably@astrojs/cloudflarewithprerenderEnvironment: 'node'),createViteLoaderbuilds a dedicated loader per environment. Every other method already uses the constructor parameter - onlygetSSREnvironment()ignored it, so the prerender handler's loader returned the unrelatedssrenvironment andgetComponentMetadata()walked the wrong module graph in dev. With Cloudflare's default workerdssr, that env is also non-runnable, making theas RunnableDevEnvironmentcast unsafe.ASTRO_VITE_ENVIRONMENT_NAMESimport.astro: patch(.changeset/fix-module-loader-prerender-env.md).@astrojs/cloudflare:prerenderEnvironment: 'node'swallows scoped<style>blocks into<template>in dev #16436. Follow-up to fix: propagate head metadata across ssr and prerender envs in dev #16292, which fixed the visible style-into-<template>symptom inastro:head-metadatabut did not touch this separate correctness bug in the per-environment module loader.Testing
tsc --noEmitonpackages/astropasses cleanly.packages/astro/test/head-propagation-prerender-env.test.jsstill passes (1/1) - confirms no regression on theastro:head-metadatapath that fix: propagate head metadata across ssr and prerender envs in dev #16292 fixed.loader.getSSREnvironment()has a single caller (getComponentMetadata), and when only thessrenv existsssrEnvironment === viteServer.environments.ssr, so the new behaviour is a strict superset of the old correct behaviour. Happy to extend thehead-propagation-prerender-envfixture with a prerendered route to exercise the prerender handler's loader directly if maintainers prefer.Docs
No docs change needed - this is a dev-server-internal correctness fix with no user-facing API or behaviour change. Users on adapters with a separate prerender env (e.g.
@astrojs/cloudflarewithprerenderEnvironment: 'node') will simply see correct head metadata for prerendered routes in dev.