diff --git a/.changeset/chilled-geese-worry.md b/.changeset/chilled-geese-worry.md new file mode 100644 index 000000000..3b1551724 --- /dev/null +++ b/.changeset/chilled-geese-worry.md @@ -0,0 +1,13 @@ +--- +'astro': major +--- + +The previously experimental features `--experimental-error-overlay` and `--experimental-prerender`, both added in v1.7.0, are now the default. + +You'll notice that the error overlay during `astro dev` has a refreshed visual design and provides more context for your errors. + +The `prerender` feature is now enabled by default when using `output: 'server'`. To prerender a particular page, add `export const prerender = true` to your frontmatter. + +> **Warning** +> Integration authors that previously relied on the exact structure of Astro's v1.0 build output may notice some changes to our output file structure. Please test your integrations to ensure compatability. +> Users that have configured a custom `vite.build.rollupOptions.output.chunkFileNames` should ensure that their Astro project is configured as an ESM Node project. Either include `"type": "module"` in your root `package.json` file or use the `.mjs` extension for `chunkFileNames`. diff --git a/packages/astro/e2e/error-cyclic.test.js b/packages/astro/e2e/error-cyclic.test.js index 5bdef236e..32cbc050a 100644 --- a/packages/astro/e2e/error-cyclic.test.js +++ b/packages/astro/e2e/error-cyclic.test.js @@ -2,7 +2,6 @@ import { expect } from '@playwright/test'; import { testFactory, getErrorOverlayContent } from './test-utils.js'; const test = testFactory({ - experimental: { errorOverlay: true }, root: './fixtures/error-cyclic/', }); diff --git a/packages/astro/e2e/error-sass.test.js b/packages/astro/e2e/error-sass.test.js index ec8ab89f2..a4e68f57b 100644 --- a/packages/astro/e2e/error-sass.test.js +++ b/packages/astro/e2e/error-sass.test.js @@ -2,7 +2,6 @@ import { expect } from '@playwright/test'; import { testFactory, getErrorOverlayContent } from './test-utils.js'; const test = testFactory({ - experimental: { errorOverlay: true }, root: './fixtures/error-sass/', }); diff --git a/packages/astro/e2e/errors.test.js b/packages/astro/e2e/errors.test.js index 0de23f7c1..ce867aa36 100644 --- a/packages/astro/e2e/errors.test.js +++ b/packages/astro/e2e/errors.test.js @@ -2,7 +2,6 @@ import { expect } from '@playwright/test'; import { getErrorOverlayContent, testFactory } from './test-utils.js'; const test = testFactory({ - experimental: { errorOverlay: true }, root: './fixtures/errors/', }); diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index c5839058a..e20d0eeed 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -83,8 +83,6 @@ export interface CLIFlags { port?: number; config?: string; drafts?: boolean; - experimentalErrorOverlay?: boolean; - experimentalPrerender?: boolean; experimentalContentCollections?: boolean; } @@ -927,46 +925,6 @@ export interface AstroUserConfig { * These flags are not guaranteed to be stable. */ experimental?: { - /** - * @docs - * @name experimental.errorOverlay - * @type {boolean} - * @default `false` - * @version 1.7.0 - * @description - * Turn on experimental support for the new error overlay component. - * - * To enable this feature, set `experimental.errorOverlay` to `true` in your Astro config: - * - * ```js - * { - * experimental: { - * errorOverlay: true, - * }, - * } - * ``` - */ - errorOverlay?: boolean; - /** - * @docs - * @name experimental.prerender - * @type {boolean} - * @default `false` - * @version 1.7.0 - * @description - * Enable experimental support for prerendered pages when generating a server. - * - * To enable this feature, set `experimental.prerender` to `true` in your Astro config: - * - * ```js - * { - * experimental: { - * prerender: true, - * }, - * } - * ``` - */ - prerender?: boolean; /** * @docs * @name experimental.contentCollections diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 11dfb1788..fd8dd75a5 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -81,7 +81,6 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir); if ( - opts.settings.config.experimental.prerender && opts.settings.config.output === 'server' && !hasPrerenderedPages(internals) ) @@ -94,7 +93,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn const ssrEntry = await import(ssrEntryURL.toString()); const builtPaths = new Set(); - if (opts.settings.config.experimental.prerender && opts.settings.config.output === 'server') { + if (opts.settings.config.output === 'server') { for (const pageData of eachPrerenderedPageData(internals)) { await generatePage(opts, internals, pageData, ssrEntry, builtPaths); } diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index c44858f74..cfb447eb9 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -95,32 +95,19 @@ export async function staticBuild(opts: StaticBuildOptions) { await clientBuild(opts, internals, clientInput); timer.generate = performance.now(); - if (!settings.config.experimental.prerender) { - if (settings.config.output === 'static') { + switch (settings.config.output) { + case 'static': { await generatePages(opts, internals); await cleanServerOutput(opts); - } else { - // Inject the manifest + return; + } + case 'server': { await injectManifest(opts, internals); - + await generatePages(opts, internals); + await cleanStaticOutput(opts, internals); info(opts.logging, null, `\n${bgMagenta(black(' finalizing server assets '))}\n`); await ssrMoveAssets(opts); - } - } else { - switch (settings.config.output) { - case 'static': { - await generatePages(opts, internals); - await cleanServerOutput(opts); - return; - } - case 'server': { - await injectManifest(opts, internals); - await generatePages(opts, internals); - await cleanStaticOutput(opts, internals); - info(opts.logging, null, `\n${bgMagenta(black(' finalizing server assets '))}\n`); - await ssrMoveAssets(opts); - return; - } + return; } } } @@ -197,12 +184,7 @@ async function clientBuild( const { settings, viteConfig } = opts; const timer = performance.now(); const ssr = settings.config.output === 'server'; - let out; - if (!opts.settings.config.experimental.prerender) { - out = ssr ? opts.buildConfig.client : settings.config.outDir; - } else { - out = ssr ? opts.buildConfig.client : getOutDirWithinCwd(settings.config.outDir); - } + const out = ssr ? opts.buildConfig.client : getOutDirWithinCwd(settings.config.outDir); // Nothing to do if there is no client-side JS. if (!input.size) { @@ -323,16 +305,6 @@ async function cleanStaticOutput(opts: StaticBuildOptions, internals: BuildInter }) ); } - - if (!opts.settings.config.experimental.prerender) { - // Clean out directly if the outDir is outside of root - if (out.toString() !== opts.settings.config.outDir.toString()) { - // Copy assets before cleaning directory if outside root - copyFiles(out, opts.settings.config.outDir); - await fs.promises.rm(out, { recursive: true }); - return; - } - } } async function cleanServerOutput(opts: StaticBuildOptions) { diff --git a/packages/astro/src/core/build/vite-plugin-prerender.ts b/packages/astro/src/core/build/vite-plugin-prerender.ts index 4ad343200..b8091c32d 100644 --- a/packages/astro/src/core/build/vite-plugin-prerender.ts +++ b/packages/astro/src/core/build/vite-plugin-prerender.ts @@ -10,9 +10,6 @@ export function vitePluginPrerender( name: 'astro:rollup-plugin-prerender', outputOptions(outputOptions) { - // No-op if `prerender` is not enabled - if (!opts.settings.config.experimental.prerender) return; - const manualChunks = outputOptions.manualChunks || Function.prototype; outputOptions.manualChunks = function (id, api, ...args) { // Defer to user-provided `manualChunks`, if it was provided. diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index 7ac8ca110..248ea9117 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -100,12 +100,6 @@ export function resolveFlags(flags: Partial): CLIFlags { host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined, drafts: typeof flags.drafts === 'boolean' ? flags.drafts : undefined, - experimentalErrorOverlay: - typeof flags.experimentalErrorOverlay === 'boolean' - ? flags.experimentalErrorOverlay - : undefined, - experimentalPrerender: - typeof flags.experimentalPrerender === 'boolean' ? flags.experimentalPrerender : undefined, experimentalContentCollections: typeof flags.experimentalContentCollections === 'boolean' ? flags.experimentalContentCollections @@ -138,8 +132,6 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags, cmd: strin // TODO: Come back here and refactor to remove this expected error. astroConfig.server.host = flags.host; } - if (flags.experimentalErrorOverlay) astroConfig.experimental.errorOverlay = true; - if (flags.experimentalPrerender) astroConfig.experimental.prerender = true; if (flags.experimentalContentCollections) astroConfig.experimental.contentCollections = true; return astroConfig; } diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index a138f9771..3db3fe884 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -48,8 +48,6 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { astroFlavoredMarkdown: false, }, experimental: { - errorOverlay: false, - prerender: false, contentCollections: false, }, }; @@ -194,8 +192,6 @@ export const AstroConfigSchema = z.object({ .default(ASTRO_CONFIG_DEFAULTS.vite), experimental: z .object({ - errorOverlay: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.errorOverlay), - prerender: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.prerender), contentCollections: z .boolean() .optional() diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 85b720d13..0e1b48e2d 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -119,7 +119,7 @@ export async function createVite( astroIntegrationsContainerPlugin({ settings, logging }), astroScriptsPageSSRPlugin({ settings }), astroHeadPropagationPlugin({ settings }), - settings.config.experimental.prerender && astroScannerPlugin({ settings, logging }), + astroScannerPlugin({ settings, logging }), ...(settings.config.experimental.contentCollections ? [ astroContentVirtualModPlugin({ settings }), diff --git a/packages/astro/src/core/errors/overlay.ts b/packages/astro/src/core/errors/overlay.ts index 464255a97..7ed3df148 100644 --- a/packages/astro/src/core/errors/overlay.ts +++ b/packages/astro/src/core/errors/overlay.ts @@ -561,25 +561,5 @@ function getOverlayCode() { } export function patchOverlay(code: string, config: AstroConfig) { - if (config.experimental.errorOverlay) { - return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay'); - } else { - // Legacy overlay - return ( - code - // Transform links in the message to clickable links - .replace( - "this.text('.message-body', message.trim());", - `const urlPattern = /(\\b(https?|ftp):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim; - function escapeHtml(unsafe){return unsafe.replace(//g, ">");} - const escapedMessage = escapeHtml(message); - this.root.querySelector(".message-body").innerHTML = escapedMessage.trim().replace(urlPattern, '$1');` - ) - .replace('', '.message-body a {\n color: #ededed;\n}\n') - // Hide `.tip` in Vite's ErrorOverlay - .replace(/\.tip \{[^}]*\}/gm, '.tip {\n display: none;\n}') - // Replace [vite] messages with [astro] - .replace(/\[vite\]/g, '[astro]') - ); - } + return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay'); } diff --git a/packages/astro/test/fixtures/config-vite/astro.config.mjs b/packages/astro/test/fixtures/config-vite/astro.config.mjs index 2e6f18a63..47a05dd8d 100644 --- a/packages/astro/test/fixtures/config-vite/astro.config.mjs +++ b/packages/astro/test/fixtures/config-vite/astro.config.mjs @@ -5,7 +5,7 @@ export default defineConfig({ build: { rollupOptions: { output: { - chunkFileNames: 'assets/testing-[name].js', + chunkFileNames: 'assets/testing-[name].mjs', assetFileNames: 'assets/testing-[name].[ext]' } }