fix(astro:assets): inject /_image endpoint with prerendered=false on serverLikeOutput (#7423)

This commit is contained in:
Benjamin MENANT 2023-06-22 09:20:35 +02:00 committed by GitHub
parent 76fcdb84dd
commit 33cdc8622a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Ensure injected `/_image` endpoint for image optimization is not prerendered on hybrid output.

View file

@ -1293,6 +1293,7 @@ export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' |
export interface InjectedRoute {
pattern: string;
entryPoint: string;
prerender?: boolean;
}
export interface AstroConfig extends z.output<typeof AstroConfigSchema> {
// Public:

View file

@ -24,7 +24,7 @@ export function createBaseSettings(config: AstroConfig): AstroSettings {
adapter: undefined,
injectedRoutes:
config.experimental.assets && isServerLikeOutput(config)
? [{ pattern: '/_image', entryPoint: 'astro/assets/image-endpoint' }]
? [{ pattern: '/_image', entryPoint: 'astro/assets/image-endpoint', prerender: false }]
: [],
pageExtensions: ['.astro', '.html', ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
contentEntryTypes: [markdownContentEntryType],

View file

@ -387,7 +387,7 @@ export function createRouteManifest(
comparator(injectedRouteToItem({ config, cwd }, a), injectedRouteToItem({ config, cwd }, b))
)
.reverse() // prepend to the routes array from lowest to highest priority
.forEach(({ pattern: name, entryPoint }) => {
.forEach(({ pattern: name, entryPoint, prerender: prerenderInjected }) => {
let resolved: string;
try {
resolved = require.resolve(entryPoint, { paths: [cwd || fileURLToPath(config.root)] });
@ -440,7 +440,7 @@ export function createRouteManifest(
component,
generate,
pathname: pathname || void 0,
prerender,
prerender: prerenderInjected ?? prerender,
});
});