You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multiple middlewares can be joined in a specified order using [`sequence()`](#sequence):
138
138
139
139
```js title="src/middleware.js"
140
-
import { sequence } from"astro/middleware";
140
+
import { sequence } from"astro:middleware";
141
141
142
142
asyncfunctionvalidation(_, next) {
143
143
console.log("validation request");
@@ -218,4 +218,4 @@ This function can be used by integrations/adapters to programmatically execute t
218
218
219
219
### `trySerializeLocals`
220
220
221
-
A low-level API that takes in any value and tries to return a serialized version (a string) of it. If the value cannot be serialized, the function will throw a runtime error.
221
+
A low-level API that takes in any value and tries to return a serialized version (a string) of it. If the value cannot be serialized, the function will throw a runtime error.
Copy file name to clipboardExpand all lines: src/content/docs/en/guides/styling.mdx
+18-6Lines changed: 18 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -531,24 +531,36 @@ If you are using Tailwind, the [typography plugin](https://tailwindcss.com/docs/
531
531
532
532
### Bundle control
533
533
534
-
When Astro builds your site for production deployment it combines your CSS into chunks. Each page on your site is its own chunk, and additionally, CSS that is shared between multiple pages is further split off into their own chunks for reuse.
534
+
When Astro builds your site for production deployment, it minifies and combines your CSS into chunks. Each page on your site gets its own chunk, and additionally, CSS that is shared between multiple pages is further split off into their own chunks for reuse.
535
535
536
-
In each of your HTML files there will be `<link rel="stylesheet">` tags added, one for each of the chunks that the pages needs.
536
+
However, when you have several pages sharing styles, some shared chunks can become really small. If all of them were sent separately, it would lead to many stylesheets requests and affect site performance. Therefore, by default Astro will link only those in your HTML above 4kB in size as `<link rel="stylesheet">` tags, while inlining smaller ones into `<style type="text/css">`. This approach provides a balance between the number of additional requests and the volume of CSS that can be cached between pages.
537
537
538
-
Sites with a large number of pages and many different shared styles can lead to many stylesheet requests and affect site performance. You can configure the `inlineStylesheets` option to reduce the number of these requests by putting (minimized) stylesheets into a `<style>` tag rather than request them externally.
538
+
You can configure the size at which stylesheets will be linked externally (in bytes) using the `assetsInlineLimit` vite build option. Note that this option affects script and image inlining as well.
539
+
540
+
```js
541
+
import { defineConfig } from'astro/config';
542
+
543
+
exportdefaultdefineConfig({
544
+
vite: {
545
+
build: {
546
+
assetsInlineLimit:1024,
547
+
}
548
+
};
549
+
});
550
+
```
551
+
552
+
If you would rather all project styles remain external, you can configure the `inlineStylesheets` build option.
539
553
540
554
```js
541
555
import { defineConfig } from'astro/config';
542
556
543
557
exportdefaultdefineConfig({
544
558
build: {
545
-
inlineStylesheets:'auto'
559
+
inlineStylesheets:'never'
546
560
}
547
561
});
548
562
```
549
563
550
-
The `'auto'` option will inline only the stylesheets that are below the `vite.build.assetsInlineLimit` threshold, reducing the number of requests for smaller sheets. Larger stylesheets, such as global ones used by all pages, will still be fetched externally and cached. This option provides a balance between the number of stylesheets loaded and the styles that can be cached between pages.
551
-
552
564
You can also set this option to `'always'` which will inline all stylesheets.
@@ -45,6 +45,31 @@ Update your project's version of Astro to the latest version using your package
45
45
</Fragment>
46
46
</PackageManagerTabs>
47
47
48
+
## Astro v3.0 Experimental Flags Removed
49
+
50
+
Remove the following experimental flags from `astro.config.mjs`:
51
+
52
+
```js del={5-8}
53
+
// astro.config.mjs
54
+
import { defineConfig } from'astro/config';
55
+
56
+
exportdefaultdefineConfig({
57
+
experimental: {
58
+
assets:true,
59
+
viewTransitions:true,
60
+
},
61
+
})
62
+
```
63
+
64
+
These features are now available by default:
65
+
66
+
-[View Transitions](/en/guides/view-transitions/) for animated page transitions and persistent islands.
67
+
-[A new image services API `astro:assets`](/en/guides/images/) for optimizing and transforming images through the new `<Image />` component and `getImage()` function. Also unlocks [relative images in Markdown, MDX and Markdoc](/en/guides/images/#update-your-markdown-mdx-and-markdoc-files) using standard `![]()` syntax.
68
+
69
+
Read more about these two exciting features and more in the 3.0 Blog post!
70
+
71
+
72
+
48
73
## Astro v3.0 Breaking Changes
49
74
50
75
Astro v3.0 includes some breaking changes, as well as the removal of some previously deprecated features. If your project doesn't work as expected after upgrading to v3.0, check this guide for an overview of all breaking changes and instructions on how to update your codebase.
@@ -74,13 +99,27 @@ Astro v3.0 drops Node 16 support entirely, so that all Astro users can take adva
74
99
75
100
You can specify Node `18.14.1` for your Astro project either in a dashboard configuration setting, or a `.nvmrc` file.
76
101
77
-
### Reserved: `src/assets/`
102
+
### Removed: `@astrojs/image`
103
+
In Astro v2.x, this package existed
104
+
105
+
Astro v3.0, it does not anymore, replaced by `astro:assets`
106
+
107
+
#### What should I do?
108
+
109
+
Migrate to `astro:assets`. In `.astro` files this is really just a replace `@astrojs/image` by `astro:assets` in most cases, however if you used the Picture component, you'll need at this time to recreate it using the `getImage` APIs.
110
+
111
+
Please see the full [v3 Image Upgrade Guide](/en/guides/images/#upgrade-to-v30-from-v2x) for details!
78
112
79
-
Astro v3.0 now includes the new image services API for optimizing your image assets. This API reserves `src/assets/` as a special folder, with a built-in import alias: `~/assets` for referencing assets located here.
113
+
114
+
### Removed: `<Markdown />` component
115
+
116
+
In Astro v2.x, Astro deprecated the `<Markdown />` component and moved it to an external package.
117
+
118
+
Astro v3.0 comletely removes the package `@astrojs/markdown-component`, so Astro's `<Markdown />` component will no longer work in your project.
80
119
81
120
#### What should I do?
82
121
83
-
No change is required, and there will be no conflicts with an existing `src/assets/` folder. However, you will now have access to the built-in import alias and can choose to rename your asset imports within your files. This folder is not required, and your assets may continued to be located anywhere.
122
+
Uninstall the `@astrojs/markdown-component` package. To continue using a similar `<Markdown />` component in your code, consider using [community integrations](https://astro.build/integrations/) that provide a similar component like https://github.com/natemoo-re/astro-remote, and be sure to update your component imports and attributes as necessary according to the integration's own documentation. Otherwise, delete all references to importing Astro's `<Markdown />` component and the component itself in your `.astro`files. You will need to rewrite your content as HTML directly or [import Markdown](/en/guides/markdown-content/#importing-markdown) from an `.md` file.
84
123
85
124
### Changed: automatic flattening of `getStaticPaths()`'s return value
86
125
@@ -321,25 +360,142 @@ Astro V3 still displays the error log, but now you can build the project.
321
360
When using an adapter that supports neither Squoosh or Sharp, Astro will now automatically use an image service that does not support processing, but still provides the other benefits of `astro:assets` such as enforcing `alt`, no CLS etc to users. Should be noted that it does no transformations or processing, but you still get all the other benefits (no CLS, alt enforced, etc). All of those benefits are part of the image service, if you make your own, you lose those benefits unless you make it yourself
322
361
323
362
324
-
### Removed: `<Markdown/>` component
363
+
### Removed: camelCase transformations
325
364
326
-
In Astro v2.x, Astro deprecated the `<Markdown/>` component and moved it to an external package.
365
+
In Astro 2.x, Astro automatically transformed camelCase CSS variable names passed to the `style` attribute of an HTML element.
327
366
328
-
Astro v3.0 comletely removes the package `@astrojs/markdown-component`, so Astro's `<Markdown/>` component will no longer work in your project.
367
+
Astro 3.0 removes backwards-compatible kebab-case transform for these camelCase CSS variable names.
329
368
330
369
#### What should I do?
331
370
332
-
Uninstall the `@astrojs/markdown-component` package. To continue using a similar `<Markdown/>` component in your code, consider using [community integrations](https://astro.build/integrations/) that provide a similar component like https://github.com/natemoo-re/astro-remote, and be sure to update your component imports and attributes as necessary according to the integration's own documentation. Otherwise, delete all references to importing Astro's `<Markdown/>` component and the component itself in your `.astro` files. You will need to rewrite your content as HTML directly or [import Markdown](/en/guides/markdown-content/#importing-markdown) from an `.md` file.
371
+
If you were relying on Astro to transform kebab-case in your styles, update your existing styles to use the camelCase version to prevent missing styles. For example:
In Astro 2.x, Astro automatically transformed camelCase CSS variable names passed to the `style` attribute of an HTML element.
385
+
```diff
386
+
<style>
387
+
div {
388
+
-color: var(--my-value);
389
+
+color: var(--myValue);
390
+
}
391
+
</style>
392
+
```
337
393
338
-
Astro 3.0 removes backwards-compatible kebab-case transform for these camelCase CSS variable names.
394
+
### Changed: default `scopedStyleStrategy`
395
+
396
+
In Astro v2.x, the default value of `scopedStyleStrategy` was `"where"`.
397
+
398
+
Astro v3.0, the default value is `"attribute"`. By default, styles are now applied using `data-*` attributes.
339
399
340
400
#### What should I do?
341
401
342
-
If you were relying on Astro to transform kebab-case in your styles, update your existing styles to use the camelCase version to prevent missing styles. For example:
402
+
To retain your project's current style scoping, update the configuration file to the previous default value:
In Astro v2.x, `import.meta.env.BASE_URL`, which derives from `base` config, is always appended a trailingSlash by default or when `trailingSlash: "ignore"` is set.
413
+
414
+
Astro v3.0 `import.meta.env.BASE_URL` is not appended with a trailingSlash by default or when `trailingSlash: "ignore"` is set. The existing behavior of `base` in combination with `trailingSlash: "always"` or `trailingSlash: "never"` is unchanged.
415
+
416
+
#### What should I do?
417
+
418
+
If your `base` already has a trailing slash, no change is needed.
419
+
420
+
If your `base` does not have a trailing slash, add one to preserve the previous behaviour:
421
+
422
+
```diff
423
+
// astro.config.mjs
424
+
-base: 'my-base',
425
+
+base: 'my-base/',
426
+
```
427
+
428
+
### Changed: Multiple JSX framework configuration
429
+
430
+
In Astro v2.x, you could use multiple JSX framework integrations (React, Solid, Preact) in the same project and Astro without having to identify which files belonged to which framework. Astro automatically scanned your components to determine which framework-specific transformations should be used, but at a performance cost.
431
+
432
+
Astro v3.0 determines which framework to use with `include` and `exclude` integration config options where you can specify files and folders on a per-framework basis. This allows Astro to better support single-framework usage, as well as advanced features like Fast Refresh.
433
+
434
+
#### What should I do?
435
+
436
+
If you are using multiple JSX frameworks in the same project, use the `include` and/or `exclude` configuration options to specify which files belong to which framework. Provide an array of files and/or folders. Wildcards may be used to include multiple file paths.
437
+
438
+
We recommend placing common framework components in the same folder (e.g. `/components/react/` and `/components/solid/`) to make specifying your includes easier, but this is not required:
439
+
440
+
```js
441
+
import { defineConfig } from'astro/config';
442
+
importpreactfrom'@astrojs/preact';
443
+
importreactfrom'@astrojs/react';
444
+
importsveltefrom'@astrojs/svelte';
445
+
importvuefrom'@astrojs/vue';
446
+
importsolidfrom'@astrojs/solid-js';
447
+
448
+
exportdefaultdefineConfig({
449
+
// Enable many frameworks to support all different kinds of components.
450
+
// No `include` is needed if you are only using a single framework!
451
+
integrations: [
452
+
preact({
453
+
include: ['**/preact/*']
454
+
}),
455
+
react({
456
+
include: ['**/react/*']
457
+
}),
458
+
solid({
459
+
include: ['**/solid/*'],
460
+
}),
461
+
]
462
+
});
463
+
```
464
+
465
+
466
+
### Removed: kebab-case transform for camelCase CSS variables
467
+
468
+
In Astro v2.x, camelCase CSS variables passed to the `style` attribute were rendered as camelCase (original) and kebab-case (incorrect by kept for backwards compatibility).
469
+
470
+
Astro v3.0 removes the kebab-case transform, and only the original camelCase CSS variable is rendered.
If you were relying on the kebab-case transform in your styles, make sure to use the camelCase version to prevent missing styles. For example:
487
+
488
+
```diff
489
+
<style>
490
+
div {
491
+
-color: var(--my-value);
492
+
+color: var(--myValue);
493
+
}
494
+
</style>
495
+
```
496
+
DUPE TO BE COMBINED
497
+
498
+
Remove backwards-compatible kebab-case transform for camelCase CSS variable names passed to the `style` attribute. If you were relying on the kebab-case transform in your styles, make sure to use the camelCase version to prevent missing styles. For example:
343
499
344
500
```astro
345
501
---
@@ -362,6 +518,82 @@ const myValue = "red"
362
518
</style>
363
519
```
364
520
521
+
### Changed entrypoint export paths
522
+
523
+
In Astro v2.x, you can import internal Astro APIs from `astro/internal/star` and `astro/runtime/server/star`.
524
+
525
+
Astro v3.0 removes the two entrypoints in favour of the existing `astro/runtime/star` entrypoint.
526
+
527
+
#### What should I do?
528
+
529
+
These are entrypoints for Astro's internal API and should not affect your project, but if you do use these entrypoints, you can migrate like below:
530
+
531
+
```diff
532
+
-import'astro/internal/index.js';
533
+
+import'astro/runtime/server/index.js';
534
+
535
+
-import'astro/server/index.js';
536
+
+import'astro/runtime/server/index.js';
537
+
```
538
+
539
+
### Small stylesheets now get inlined by default
540
+
In Astro v2.x, all project stylesheets were sent lnd u could opt-in to inlining them by using the `build.inlineStylesheets` configuration.
541
+
542
+
were sent as link tags by default and you could opt in to inlining them
543
+
544
+
Astro v3.0 defaults `inlineStylesheets` to "auto", which means stylesheets smaller than 4kB get included in the initial response.
545
+
546
+
#### What should I do?
547
+
Nothing, this change does not require any migration. To go back to the old behavior, configure `inlineStylesheets` to "never"
548
+
549
+
```diff
550
+
exportdefaultdefineConfig({
551
+
build: {
552
+
+ inlineStylesheets: "never"
553
+
}
554
+
})
555
+
```
556
+
557
+
### Changed implementation of `class:list` directive
558
+
In Astro v2.x, `class:list` used a custom implementation inspired by [`clsx`](https://github.com/lukeed/clsx) with a few extra features like deduplication and `Set` support.
559
+
560
+
In Astro v3.0, `class:list` uses [`clsx`](https://github.com/lukeed/clsx) directly, which does not support deduplication or `Set` values.
561
+
562
+
#### What should I do?
563
+
564
+
Replace any `Set` elements passed to the `class:list` directive with a plain `Array`.
565
+
566
+
```diff
567
+
<Componentclass:list={[
568
+
'a',
569
+
'b',
570
+
-newSet(['c', 'd'])
571
+
+ ['c', 'd']
572
+
]} />
573
+
```
574
+
575
+
### Changed behavior of `class:list` directive for components
576
+
577
+
In Astro v2.x, `class:list` values were sent to components via `Astro.props['class:list']`.
578
+
579
+
In Astro v3.0, `class:list` values are normalized into a string before being sent to components via `Astro.props['class']`
580
+
581
+
#### What should I do?
582
+
583
+
Remove any code that expects to receive the `class:list` prop.
0 commit comments