Skip to content

Unflag experimental features #5728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/chilled-geese-worry.md
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 0 additions & 1 deletion packages/astro/e2e/error-cyclic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
});

Expand Down
1 change: 0 additions & 1 deletion packages/astro/e2e/error-sass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
});

Expand Down
1 change: 0 additions & 1 deletion packages/astro/e2e/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
});

Expand Down
42 changes: 0 additions & 42 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ export interface CLIFlags {
port?: number;
config?: string;
drafts?: boolean;
experimentalErrorOverlay?: boolean;
experimentalPrerender?: boolean;
experimentalContentCollections?: boolean;
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -94,7 +93,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
const ssrEntry = await import(ssrEntryURL.toString());
const builtPaths = new Set<string>();

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);
}
Expand Down
46 changes: 9 additions & 37 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions packages/astro/src/core/build/vite-plugin-prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions packages/astro/src/core/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ export function resolveFlags(flags: Partial<Flags>): 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
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
astroFlavoredMarkdown: false,
},
experimental: {
errorOverlay: false,
prerender: false,
contentCollections: false,
},
};
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
22 changes: 1 addition & 21 deletions packages/astro/src/core/errors/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "&lt;").replace(/>/g, "&gt;");}
const escapedMessage = escapeHtml(message);
this.root.querySelector(".message-body").innerHTML = escapedMessage.trim().replace(urlPattern, '<a href="$1" target="_blank">$1</a>');`
)
.replace('</style>', '.message-body a {\n color: #ededed;\n}\n</style>')
// 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');
}
2 changes: 1 addition & 1 deletion packages/astro/test/fixtures/config-vite/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
}
}
Expand Down