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 { export interface InjectedRoute {
pattern: string; pattern: string;
entryPoint: string; entryPoint: string;
prerender?: boolean;
} }
export interface AstroConfig extends z.output<typeof AstroConfigSchema> { export interface AstroConfig extends z.output<typeof AstroConfigSchema> {
// Public: // Public:

View file

@ -24,7 +24,7 @@ export function createBaseSettings(config: AstroConfig): AstroSettings {
adapter: undefined, adapter: undefined,
injectedRoutes: injectedRoutes:
config.experimental.assets && isServerLikeOutput(config) 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], pageExtensions: ['.astro', '.html', ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
contentEntryTypes: [markdownContentEntryType], contentEntryTypes: [markdownContentEntryType],

View file

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