From cf9a704c6b238bf8b36b0e02444cf26a4ba7f255 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 28 Aug 2024 16:49:02 -0400 Subject: [PATCH 1/3] Remove prerender option from injectRoute --- .changeset/two-beans-try.md | 8 ++++++++ packages/astro/src/actions/index.ts | 1 - packages/astro/src/actions/runtime/route.ts | 2 ++ packages/astro/src/assets/endpoint/config.ts | 1 - packages/astro/src/core/routing/manifest/create.ts | 4 ++-- packages/astro/src/types/public/integrations.ts | 1 - .../fixtures/reuse-injected-entrypoint/astro.config.mjs | 6 +----- packages/integrations/web-vitals/src/index.ts | 1 - 8 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 .changeset/two-beans-try.md diff --git a/.changeset/two-beans-try.md b/.changeset/two-beans-try.md new file mode 100644 index 000000000000..4c205e410264 --- /dev/null +++ b/.changeset/two-beans-try.md @@ -0,0 +1,8 @@ +--- +'@astrojs/web-vitals': major +'astro': major +--- + +Remove the prerender option from injectRoute + +The `injectRoute` integration method no longer accepts `prerender: true`. Instead the route's entrypoint needs to contain `export const prerender = true`, the same as non-injected routes. diff --git a/packages/astro/src/actions/index.ts b/packages/astro/src/actions/index.ts index 61f5a00cc3ab..b6ed62b7d90f 100644 --- a/packages/astro/src/actions/index.ts +++ b/packages/astro/src/actions/index.ts @@ -40,7 +40,6 @@ export default function astroActions({ params.injectRoute({ pattern: '/_actions/[...path]', entrypoint: 'astro/actions/runtime/route.js', - prerender: false, }); params.addMiddleware({ diff --git a/packages/astro/src/actions/runtime/route.ts b/packages/astro/src/actions/runtime/route.ts index 7279a093d07e..0e439ac0631f 100644 --- a/packages/astro/src/actions/runtime/route.ts +++ b/packages/astro/src/actions/runtime/route.ts @@ -3,6 +3,8 @@ import { formContentTypes, hasContentType } from './utils.js'; import { getAction } from './virtual/get-action.js'; import { serializeActionResult } from './virtual/shared.js'; +export const prerender = false; + export const POST: APIRoute = async (context) => { const { request, url } = context; const baseAction = await getAction(url.pathname); diff --git a/packages/astro/src/assets/endpoint/config.ts b/packages/astro/src/assets/endpoint/config.ts index ff9dcc79a807..378b4cde94e1 100644 --- a/packages/astro/src/assets/endpoint/config.ts +++ b/packages/astro/src/assets/endpoint/config.ts @@ -8,7 +8,6 @@ export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'buil settings.injectedRoutes.push({ pattern: '/_image', entrypoint: endpointEntrypoint, - prerender: false, }); return settings; diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 858c2b9f2e6e..b90b28879d0c 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -277,7 +277,7 @@ function createInjectedRoutes({ settings, cwd }: CreateRouteManifestParams): Rou const routes: RouteData[] = []; for (const injectedRoute of settings.injectedRoutes) { - const { pattern: name, entrypoint, prerender: prerenderInjected } = injectedRoute; + const { pattern: name, entrypoint } = injectedRoute; let resolved: string; try { resolved = require.resolve(entrypoint, { paths: [cwd || fileURLToPath(config.root)] }); @@ -320,7 +320,7 @@ function createInjectedRoutes({ settings, cwd }: CreateRouteManifestParams): Rou component, generate, pathname: pathname || void 0, - prerender: prerenderInjected ?? prerender, + prerender, fallbackRoutes: [], }); } diff --git a/packages/astro/src/types/public/integrations.ts b/packages/astro/src/types/public/integrations.ts index a65f2513b0a7..09fb267f6a49 100644 --- a/packages/astro/src/types/public/integrations.ts +++ b/packages/astro/src/types/public/integrations.ts @@ -139,7 +139,6 @@ export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' | export interface InjectedRoute { pattern: string; entrypoint: string; - prerender?: boolean; } export interface ResolvedInjectedRoute extends InjectedRoute { diff --git a/packages/astro/test/fixtures/reuse-injected-entrypoint/astro.config.mjs b/packages/astro/test/fixtures/reuse-injected-entrypoint/astro.config.mjs index 266e31c07f93..26e993150381 100644 --- a/packages/astro/test/fixtures/reuse-injected-entrypoint/astro.config.mjs +++ b/packages/astro/test/fixtures/reuse-injected-entrypoint/astro.config.mjs @@ -10,25 +10,21 @@ export default defineConfig({ injectRoute({ pattern: `/injected-a`, entrypoint: './src/to-inject.astro', - prerender: true, }); injectRoute({ pattern: `/injected-b`, entrypoint: './src/to-inject.astro', - prerender: true, }); injectRoute({ pattern: `/dynamic-a/[id]`, entrypoint: './src/[id].astro', - prerender: true, }); injectRoute({ pattern: `/dynamic-b/[id]`, entrypoint: './src/[id].astro', - prerender: true, }); }, }, }, ], -}); \ No newline at end of file +}); diff --git a/packages/integrations/web-vitals/src/index.ts b/packages/integrations/web-vitals/src/index.ts index 02293ac6f0c6..68aea2b93888 100644 --- a/packages/integrations/web-vitals/src/index.ts +++ b/packages/integrations/web-vitals/src/index.ts @@ -33,7 +33,6 @@ export default function webVitals({ deprecated }: { deprecated?: boolean } = {}) injectRoute({ entrypoint: '@astrojs/web-vitals/endpoint', pattern: WEB_VITALS_ENDPOINT_PATH + '/[...any]', - prerender: false, }); // Client-side performance measurement script. injectScript('page', `import '@astrojs/web-vitals/client-script';`); From 0c3710910ce46c76da150d0491739185687c7310 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Thu, 12 Sep 2024 17:10:59 +0200 Subject: [PATCH 2/3] feat: remove stuff --- packages/astro/src/actions/integration.ts | 1 - packages/astro/src/integrations/hooks.ts | 7 ------- 2 files changed, 8 deletions(-) diff --git a/packages/astro/src/actions/integration.ts b/packages/astro/src/actions/integration.ts index 830420836a3d..83b77429d35f 100644 --- a/packages/astro/src/actions/integration.ts +++ b/packages/astro/src/actions/integration.ts @@ -21,7 +21,6 @@ export default function astroIntegrationActionsRouteHandler({ params.injectRoute({ pattern: '/_actions/[...path]', entrypoint: 'astro/actions/runtime/route.js', - prerender: false, }); params.addMiddleware({ diff --git a/packages/astro/src/integrations/hooks.ts b/packages/astro/src/integrations/hooks.ts index 0c40e60cdb96..0c7882689264 100644 --- a/packages/astro/src/integrations/hooks.ts +++ b/packages/astro/src/integrations/hooks.ts @@ -192,13 +192,6 @@ export async function runHookConfigSetup({ return { ...updatedConfig }; }, injectRoute: (injectRoute) => { - if (injectRoute.entrypoint == null && 'entryPoint' in injectRoute) { - logger.warn( - null, - `The injected route "${injectRoute.pattern}" by ${integration.name} specifies the entry point with the "entryPoint" property. This property is deprecated, please use "entrypoint" instead.`, - ); - injectRoute.entrypoint = injectRoute.entryPoint as string; - } updatedSettings.injectedRoutes.push(injectRoute); }, addWatchFile: (path) => { From d200fd853c03ffaaa6e636eea178df378418d9d7 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Thu, 12 Sep 2024 17:36:19 +0200 Subject: [PATCH 3/3] Update .changeset/two-beans-try.md Co-authored-by: Sarah Rainsberger --- .changeset/two-beans-try.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.changeset/two-beans-try.md b/.changeset/two-beans-try.md index 4c205e410264..4181bdee569e 100644 --- a/.changeset/two-beans-try.md +++ b/.changeset/two-beans-try.md @@ -3,6 +3,14 @@ 'astro': major --- -Remove the prerender option from injectRoute +Removes the `prerender` option from `injectRoute` in the Integrations API. -The `injectRoute` integration method no longer accepts `prerender: true`. Instead the route's entrypoint needs to contain `export const prerender = true`, the same as non-injected routes. +The `injectRoute` integration method no longer accepts `prerender: true`. + +Instead, add the `prerender` export to your injected route like you would for other routes defined in the `src/pages` directory: + +```astro +--- +export const prerender = true +--- +```