Skip to content
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

Switch build.inlineStylesheets default to auto #8118

Merged
merged 8 commits into from
Aug 18, 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
19 changes: 19 additions & 0 deletions .changeset/smart-numbers-shout.md
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol How can I not approve this?


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',
},
});
```
4 changes: 2 additions & 2 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ export interface AstroUserConfig {
* @docs
* @name build.inlineStylesheets
* @type {('always' | 'auto' | 'never')}
* @default `never`
* @default `auto`
* @version 2.6.0
* @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:
Expand All @@ -847,7 +847,7 @@ export interface AstroUserConfig {
* ```js
* {
* build: {
* inlineStylesheets: `auto`,
* inlineStylesheets: `never`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up that I also updated here, since we typically show a setting that would need to be set, and you wouldn't need to set auto specifically now that it's the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving me again!
🙏

* },
* }
* ```
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ASTRO_CONFIG_DEFAULTS = {
assets: '_astro',
serverEntry: 'entry.mjs',
redirects: true,
inlineStylesheets: 'never',
inlineStylesheets: 'auto',
split: false,
excludeMiddleware: false,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/alias-tsconfig-baseurl-only.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('Aliases with tsconfig.json - baseUrl only', () => {

before(async () => {
fixture = await loadFixture({
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
root: './fixtures/alias-tsconfig-baseurl-only/',
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/alias-tsconfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('Aliases with tsconfig.json', () => {

before(async () => {
fixture = await loadFixture({
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
root: './fixtures/alias-tsconfig/',
});
});
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/test/asset-url-base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('Asset URL resolution in build', () => {
fixture = await loadFixture({
root: './fixtures/asset-url-base/',
site: 'http://example.com/sub/path/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand All @@ -30,6 +32,8 @@ describe('Asset URL resolution in build', () => {
root: './fixtures/asset-url-base/',
site: 'http://example.com/sub/path/',
base: '/another/base/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/test/astro-client-only.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ describe('Client only components', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-client-only/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down Expand Up @@ -72,6 +74,8 @@ describe('Client only components subpath', () => {
site: 'https://site.com',
base: '/blog',
root: './fixtures/astro-client-only/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
5 changes: 5 additions & 0 deletions packages/astro/test/astro-css-bundling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('CSS Bundling', function () {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-css-bundling/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build({ mode: 'production' });
});
Expand Down Expand Up @@ -76,6 +78,9 @@ describe('CSS Bundling', function () {
fixture = await loadFixture({
root: './fixtures/astro-css-bundling/',

// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },

vite: {
build: {
rollupOptions: {
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/test/astro-directives.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ describe('Directives', async () => {
let fixture;

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();
});

Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/astro-head.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('Head in its own component', () => {
root: './fixtures/astro-head/',
site: 'https://mysite.dev/',
base: '/blog',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/build-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('build assets (static)', () => {
fixture = await loadFixture({
root: './fixtures/build-assets/',
integrations: [preact()],
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down Expand Up @@ -57,6 +59,7 @@ describe('build assets (static)', () => {
integrations: [preact()],
build: {
assets: 'custom-assets',
inlineStylesheets: 'never',
},
});
await fixture.build();
Expand Down Expand Up @@ -96,6 +99,8 @@ describe('build assets (server)', () => {
root: './fixtures/build-assets/',
integrations: [preact()],
adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down Expand Up @@ -140,6 +145,7 @@ describe('build assets (server)', () => {
integrations: [preact()],
build: {
assets: 'custom-assets',
inlineStylesheets: 'never',
},
adapter: testAdapter(),
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/component-library.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('Component Libraries', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/component-library/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
});

Expand Down
6 changes: 5 additions & 1 deletion packages/astro/test/config-vite-css-target.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ let fixture;

describe('CSS', function () {
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', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/test/config-vite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ describe('Vite Config', async () => {
let fixture;

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();
});

Expand Down
4 changes: 4 additions & 0 deletions packages/astro/test/content-collections-render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('Content Collections - render()', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/content/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down Expand Up @@ -106,6 +108,8 @@ describe('Content Collections - render()', () => {
output: 'server',
root: './fixtures/content/',
adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/css-import-as-inline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ describe('Importing raw/inlined CSS', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/css-import-as-inline/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
});
describe('Build', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/test/css-no-code-split.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ describe('vite.build.cssCodeSplit: false', () => {
let fixture;

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();
});

Expand Down
4 changes: 4 additions & 0 deletions packages/astro/test/css-order-import.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('CSS ordering - import order', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/css-order-import/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
});

Expand Down Expand Up @@ -133,6 +135,8 @@ describe('CSS ordering - import order', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/css-order-dynamic-import/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/css-order-layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('CSS ordering - import order with layouts', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/css-order-layout/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
});

Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/css-order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ describe('CSS production ordering', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/css-order/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/glob-pages-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('Astro.glob on pages/ directory', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/glob-pages-css/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/head-injection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ describe('Head injection', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/head-injection/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
});

Expand Down
6 changes: 5 additions & 1 deletion packages/astro/test/lazy-layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ describe('Lazily imported layouts', () => {
let fixture;

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();
});

Expand Down
8 changes: 7 additions & 1 deletion packages/astro/test/minification-html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ describe('HTML minification', () => {
describe('Build SSG', () => {
let fixture;
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();
});

Expand All @@ -64,6 +68,8 @@ describe('HTML minification', () => {
root: './fixtures/minification-html/',
output: 'server',
adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/page-level-styles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ describe('Page-level styles', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/page-level-styles/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/postcss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('PostCSS', function () {
this.timeout(45000); // test needs a little more time in CI
fixture = await loadFixture({
root: './fixtures/postcss',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();

Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/remote-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('Remote CSS', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/remote-css/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/root-srcdir-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('srcDir', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/root-srcdir-css/',
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
Expand Down
Loading
Loading