Switch build.inlineStylesheets default to auto (#8118)

* switch inlineStylesheets default

* use previous default for astro/test

* use previous default for content-collections-render.test.js

* integrations: node, deno, mdx, markdown

* typedocs: switch inlineStylesheets default

* Update example to show non-default

* add changeset

* reword changeset

---------

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
Arsh 2023-08-18 12:22:06 +05:30 committed by GitHub
parent 2540feedb0
commit 8a5b0c1f3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 141 additions and 18 deletions

View file

@ -0,0 +1,19 @@
---
'astro': patch
---
Astro is smarter about CSS! Small stylesheets are now inlined by default, and no longer incur the cost of additional requests to your server. Your visitors will have to wait less before they see your pages, especially those in remote locations or in a subway.
This may not be news to you if you had opted-in via the `build.inlineStylesheets` configuration. Stabilized in Astro 2.6 and set to "auto" by default for Starlight, this configuration allows you to reduce the number of requests for stylesheets by inlining them into <style> tags. The new default is "auto", which selects assets smaller than 4kB and includes them in the initial response.
To go back to the previous default behavior, change `build.inlineStylesheets` to "never".
```ts
import { defineConfig } from 'astro/config';
export default defineConfig({
build: {
inlineStylesheets: 'never',
},
});
```

View file

@ -836,7 +836,7 @@ export interface AstroUserConfig {
* @docs * @docs
* @name build.inlineStylesheets * @name build.inlineStylesheets
* @type {('always' | 'auto' | 'never')} * @type {('always' | 'auto' | 'never')}
* @default `never` * @default `auto`
* @version 2.6.0 * @version 2.6.0
* @description * @description
* Control whether project styles are sent to the browser in a separate css file or inlined into `<style>` tags. Choose from the following options: * Control whether project styles are sent to the browser in a separate css file or inlined into `<style>` tags. Choose from the following options:
@ -847,7 +847,7 @@ export interface AstroUserConfig {
* ```js * ```js
* { * {
* build: { * build: {
* inlineStylesheets: `auto`, * inlineStylesheets: `never`,
* }, * },
* } * }
* ``` * ```

View file

@ -25,7 +25,7 @@ const ASTRO_CONFIG_DEFAULTS = {
assets: '_astro', assets: '_astro',
serverEntry: 'entry.mjs', serverEntry: 'entry.mjs',
redirects: true, redirects: true,
inlineStylesheets: 'never', inlineStylesheets: 'auto',
split: false, split: false,
excludeMiddleware: false, excludeMiddleware: false,
}, },

View file

@ -29,6 +29,8 @@ describe('Aliases with tsconfig.json - baseUrl only', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
root: './fixtures/alias-tsconfig-baseurl-only/', root: './fixtures/alias-tsconfig-baseurl-only/',
}); });
}); });

View file

@ -29,6 +29,8 @@ describe('Aliases with tsconfig.json', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
root: './fixtures/alias-tsconfig/', root: './fixtures/alias-tsconfig/',
}); });
}); });

View file

@ -12,6 +12,8 @@ describe('Asset URL resolution in build', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/asset-url-base/', root: './fixtures/asset-url-base/',
site: 'http://example.com/sub/path/', site: 'http://example.com/sub/path/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });
@ -30,6 +32,8 @@ describe('Asset URL resolution in build', () => {
root: './fixtures/asset-url-base/', root: './fixtures/asset-url-base/',
site: 'http://example.com/sub/path/', site: 'http://example.com/sub/path/',
base: '/another/base/', base: '/another/base/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -9,6 +9,8 @@ describe('Client only components', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/astro-client-only/', root: './fixtures/astro-client-only/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });
@ -72,6 +74,8 @@ describe('Client only components subpath', () => {
site: 'https://site.com', site: 'https://site.com',
base: '/blog', base: '/blog',
root: './fixtures/astro-client-only/', root: './fixtures/astro-client-only/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -26,6 +26,8 @@ describe('CSS Bundling', function () {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/astro-css-bundling/', root: './fixtures/astro-css-bundling/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build({ mode: 'production' }); await fixture.build({ mode: 'production' });
}); });
@ -76,6 +78,9 @@ describe('CSS Bundling', function () {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/astro-css-bundling/', root: './fixtures/astro-css-bundling/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
vite: { vite: {
build: { build: {
rollupOptions: { rollupOptions: {

View file

@ -6,7 +6,11 @@ describe('Directives', async () => {
let fixture; let fixture;
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-directives/' }); fixture = await loadFixture({
root: './fixtures/astro-directives/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' }
});
await fixture.build(); await fixture.build();
}); });

View file

@ -10,6 +10,8 @@ describe('Head in its own component', () => {
root: './fixtures/astro-head/', root: './fixtures/astro-head/',
site: 'https://mysite.dev/', site: 'https://mysite.dev/',
base: '/blog', base: '/blog',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -13,6 +13,8 @@ describe('build assets (static)', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/build-assets/', root: './fixtures/build-assets/',
integrations: [preact()], integrations: [preact()],
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });
@ -57,6 +59,7 @@ describe('build assets (static)', () => {
integrations: [preact()], integrations: [preact()],
build: { build: {
assets: 'custom-assets', assets: 'custom-assets',
inlineStylesheets: 'never',
}, },
}); });
await fixture.build(); await fixture.build();
@ -96,6 +99,8 @@ describe('build assets (server)', () => {
root: './fixtures/build-assets/', root: './fixtures/build-assets/',
integrations: [preact()], integrations: [preact()],
adapter: testAdapter(), adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });
@ -140,6 +145,7 @@ describe('build assets (server)', () => {
integrations: [preact()], integrations: [preact()],
build: { build: {
assets: 'custom-assets', assets: 'custom-assets',
inlineStylesheets: 'never',
}, },
adapter: testAdapter(), adapter: testAdapter(),
}); });

View file

@ -13,6 +13,8 @@ describe('Component Libraries', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/component-library/', root: './fixtures/component-library/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });

View file

@ -10,7 +10,11 @@ let fixture;
describe('CSS', function () { describe('CSS', function () {
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/config-vite-css-target/' }); fixture = await loadFixture({
root: './fixtures/config-vite-css-target/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
}); });
describe('build', () => { describe('build', () => {

View file

@ -6,7 +6,11 @@ describe('Vite Config', async () => {
let fixture; let fixture;
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/config-vite/' }); fixture = await loadFixture({
root: './fixtures/config-vite/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build(); await fixture.build();
}); });

View file

@ -13,6 +13,8 @@ describe('Content Collections - render()', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/content/', root: './fixtures/content/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });
@ -106,6 +108,8 @@ describe('Content Collections - render()', () => {
output: 'server', output: 'server',
root: './fixtures/content/', root: './fixtures/content/',
adapter: testAdapter(), adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -7,6 +7,8 @@ describe('Importing raw/inlined CSS', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/css-import-as-inline/', root: './fixtures/css-import-as-inline/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });
describe('Build', () => { describe('Build', () => {

View file

@ -7,7 +7,11 @@ describe('vite.build.cssCodeSplit: false', () => {
let fixture; let fixture;
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/css-no-code-split/' }); fixture = await loadFixture({
root: './fixtures/css-no-code-split/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build(); await fixture.build();
}); });

View file

@ -8,6 +8,8 @@ describe('CSS ordering - import order', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/css-order-import/', root: './fixtures/css-order-import/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });
@ -133,6 +135,8 @@ describe('CSS ordering - import order', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/css-order-dynamic-import/', root: './fixtures/css-order-dynamic-import/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -8,6 +8,8 @@ describe('CSS ordering - import order with layouts', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/css-order-layout/', root: './fixtures/css-order-layout/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });

View file

@ -75,6 +75,8 @@ describe('CSS production ordering', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/css-order/', root: './fixtures/css-order/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -8,6 +8,8 @@ describe('Astro.glob on pages/ directory', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/glob-pages-css/', root: './fixtures/glob-pages-css/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -9,6 +9,8 @@ describe('Head injection', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/head-injection/', root: './fixtures/head-injection/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });

View file

@ -7,7 +7,11 @@ describe('Lazily imported layouts', () => {
let fixture; let fixture;
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/lazy-layout/' }); fixture = await loadFixture({
root: './fixtures/lazy-layout/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build(); await fixture.build();
}); });

View file

@ -47,7 +47,11 @@ describe('HTML minification', () => {
describe('Build SSG', () => { describe('Build SSG', () => {
let fixture; let fixture;
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/minification-html/' }); fixture = await loadFixture({
root: './fixtures/minification-html/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build(); await fixture.build();
}); });
@ -64,6 +68,8 @@ describe('HTML minification', () => {
root: './fixtures/minification-html/', root: './fixtures/minification-html/',
output: 'server', output: 'server',
adapter: testAdapter(), adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -9,6 +9,8 @@ describe('Page-level styles', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/page-level-styles/', root: './fixtures/page-level-styles/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -10,6 +10,8 @@ describe('PostCSS', function () {
this.timeout(45000); // test needs a little more time in CI this.timeout(45000); // test needs a little more time in CI
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/postcss', root: './fixtures/postcss',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();

View file

@ -8,6 +8,8 @@ describe('Remote CSS', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/remote-css/', root: './fixtures/remote-css/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -8,6 +8,8 @@ describe('srcDir', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/root-srcdir-css/', root: './fixtures/root-srcdir-css/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -12,6 +12,8 @@ describe('scopedStyleStrategy', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/scoped-style-strategy/', root: './fixtures/scoped-style-strategy/',
scopedStyleStrategy: 'where', scopedStyleStrategy: 'where',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
@ -40,6 +42,8 @@ describe('scopedStyleStrategy', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/scoped-style-strategy/', root: './fixtures/scoped-style-strategy/',
scopedStyleStrategy: 'class', scopedStyleStrategy: 'class',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
@ -67,6 +71,8 @@ describe('scopedStyleStrategy', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/scoped-style-strategy/', root: './fixtures/scoped-style-strategy/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();

View file

@ -12,6 +12,8 @@ describe('404 and 500 pages', () => {
root: './fixtures/ssr-api-route-custom-404/', root: './fixtures/ssr-api-route-custom-404/',
output: 'server', output: 'server',
adapter: testAdapter(), adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });

View file

@ -11,6 +11,8 @@ describe('SSR Assets', () => {
root: './fixtures/ssr-assets/', root: './fixtures/ssr-assets/',
output: 'server', output: 'server',
adapter: testAdapter(), adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -25,6 +25,8 @@ describe('Dynamic pages in SSR', () => {
}, },
], ],
adapter: testAdapter(), adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -12,6 +12,8 @@ describe('astro:ssr-manifest', () => {
root: './fixtures/ssr-manifest/', root: './fixtures/ssr-manifest/',
output: 'server', output: 'server',
adapter: testAdapter(), adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -26,6 +26,8 @@ describe('astro:ssr-manifest, split', () => {
currentRoutes = routes; currentRoutes = routes;
}, },
}), }),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -34,6 +34,8 @@ describe('Static build', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/static-build/', root: './fixtures/static-build/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
await fixture.build({ logging }); await fixture.build({ logging });
}); });

View file

@ -6,7 +6,11 @@ describe('Loading virtual Astro files', () => {
let fixture; let fixture;
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/virtual-astro-file/' }); fixture = await loadFixture({
root: './fixtures/virtual-astro-file/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build(); await fixture.build();
}); });

View file

@ -48,14 +48,11 @@ Deno.test({
const html = await resp.text(); const html = await resp.text();
const doc = new DOMParser().parseFromString(html, `text/html`); const doc = new DOMParser().parseFromString(html, `text/html`);
const link = doc!.querySelector('link'); const style = doc!.querySelector('style');
const href = link!.getAttribute('href');
resp = await fetch(new URL(href!, app.url)); assertEquals(style?.getAttribute('type'), 'text/css');
assertEquals(resp.status, 200);
const ct = resp.headers.get('content-type'); assert(style?.textContent?.includes('Courier New'))
assertEquals(ct, 'text/css; charset=UTF-8');
await resp.body!.cancel();
}); });
await t.step('Correctly loads run-time env variables', async () => { await t.step('Correctly loads run-time env variables', async () => {

View file

@ -8,6 +8,8 @@ describe('Markdoc - propagated assets', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: new URL('./fixtures/propagated-assets/', import.meta.url), root: new URL('./fixtures/propagated-assets/', import.meta.url),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });

View file

@ -12,6 +12,8 @@ describe('Head injection w/ MDX', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: new URL('./fixtures/css-head-mdx/', import.meta.url), root: new URL('./fixtures/css-head-mdx/', import.meta.url),
integrations: [mdx()], integrations: [mdx()],
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });

View file

@ -8,6 +8,8 @@ describe('MDX Page', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: new URL('./fixtures/mdx-page/', import.meta.url), root: new URL('./fixtures/mdx-page/', import.meta.url),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
}); });
}); });

View file

@ -101,7 +101,7 @@ describe('Prerender 404', () => {
const $ = cheerio.load(html); const $ = cheerio.load(html);
// length will be 0 if the stylesheet does not get included // length will be 0 if the stylesheet does not get included
expect($('link[rel=stylesheet]')).to.have.a.lengthOf(1); expect($('style[type="text/css"]')).to.have.a.lengthOf(1);
}); });
}); });