Skip to content

Commit

Permalink
fix(astro:assets): inject /_image endpoint with prerendered=false on …
Browse files Browse the repository at this point in the history
…serverLikeOutput (#7423)
  • Loading branch information
bmenant authored Jun 22, 2023
1 parent 76fcdb8 commit 33cdc86
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-flies-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Ensure injected `/_image` endpoint for image optimization is not prerendered on hybrid output.
1 change: 1 addition & 0 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)] });
Expand Down Expand Up @@ -440,7 +440,7 @@ export function createRouteManifest(
component,
generate,
pathname: pathname || void 0,
prerender,
prerender: prerenderInjected ?? prerender,
});
});

Expand Down

0 comments on commit 33cdc86

Please sign in to comment.