Skip to content

Releases: withastro/astro

astro@5.10.1

23 Jun 11:20
339ee27
Compare
Choose a tag to compare

Patch Changes

  • #13988 609044c Thanks @ascorbic! - Fixes a bug in live collections that caused it to incorrectly complain about the collection being defined in the wrong file

  • #13909 b258d86 Thanks @isVivek99! - Fixes rendering of special boolean attributes for custom elements

  • #13983 e718375 Thanks @florian-lefebvre! - Fixes a case where the toolbar audit would incorrectly flag images processed by Astro in content collections documents

  • #13999 f077b68 Thanks @ascorbic! - Adds lastModified field to experimental live collection cache hints

    Live loaders can now set a lastModified field in the cache hints for entries and collections to indicate when the data was last modified. This is then available in the cacheHint field returned by getCollection and getEntry.

  • #13987 08f34b1 Thanks @ematipico! - Adds an informative message in dev mode when the CSP feature is enabled.

  • #14005 82aad62 Thanks @ematipico! - Fixes a bug where inline styles and scripts didn't work when CSP was enabled. Now when adding <styles> elements inside an Astro component, their hashes care correctly computed.

  • #13985 0b4c641 Thanks @jsparkdev! - Updates wrong link

astro@5.10.0

19 Jun 11:07
0ad80d9
Compare
Choose a tag to compare

Minor Changes

  • #13917 e615216 Thanks @ascorbic! - Adds a new priority attribute for Astro's image components.

    This change introduces a new priority option for the <Image /> and <Picture /> components, which automatically sets the loading, decoding, and fetchpriority attributes to their optimal values for above-the-fold images which should be loaded immediately.

    It is a boolean prop, and you can use the shorthand syntax by simply adding priority as a prop to the <Image /> or <Picture /> component. When set, it will apply the following attributes:

    • loading="eager"
    • decoding="sync"
    • fetchpriority="high"

    The individual attributes can still be set manually if you need to customize your images further.

    By default, the Astro <Image /> component generates <img> tags that lazy-load their content by setting loading="lazy" and decoding="async". This improves performance by deferring the loading of images that are not immediately visible in the viewport, and gives the best scores in performance audits like Lighthouse.

    The new priority attribute will override those defaults and automatically add the best settings for your high-priority assets.

    This option was previously available for experimental responsive images, but now it is a standard feature for all images.

    Usage

    <Image src="/path/to/image.jpg" alt="An example image" priority />

    [!Note]
    You should only use the priority option for images that are critical to the initial rendering of the page, and ideally only one image per page. This is often an image identified as the LCP element when running Lighthouse tests. Using it for too many images will lead to performance issues, as it forces the browser to load those images immediately, potentially blocking the rendering of other content.

  • #13917 e615216 Thanks @ascorbic! - The responsive images feature introduced behind a flag in v5.0.0 is no longer experimental and is available for general use.

    The new responsive images feature in Astro automatically generates optimized images for different screen sizes and resolutions, and applies the correct attributes to ensure that images are displayed correctly on all devices.

    Enable the image.responsiveStyles option in your Astro config. Then, set a layout attribute on any or component, or configure a default image.layout, for instantly responsive images with automatically generated srcset and sizes attributes based on the image's dimensions and the layout type.

    Displaying images correctly on the web can be challenging, and is one of the most common performance issues seen in sites. This new feature simplifies the most challenging part of the process: serving your site visitor an image optimized for their viewing experience, and for your website's performance.

    For full details, see the updated Image guide.

    Migration from Experimental Responsive Images

    The experimental.responsiveImages flag has been removed, and all experimental image configuration options have been renamed to their final names.

    If you were using the experimental responsive images feature, you'll need to update your configuration:

    Remove the experimental flag

    export default defineConfig({
       experimental: {
    -    responsiveImages: true,
       },
    });

    Update image configuration options

    During the experimental phase, default styles were applied automatically to responsive images. Now, you need to explicitly set the responsiveStyles option to true if you want these styles applied.

    export default defineConfig({
      image: {
    +    responsiveStyles: true,
      },
    });

    The experimental image configuration options have been renamed:

    Before:

    export default defineConfig({
      image: {
        experimentalLayout: 'constrained',
        experimentalObjectFit: 'cover',
        experimentalObjectPosition: 'center',
        experimentalBreakpoints: [640, 750, 828, 1080, 1280],
        experimentalDefaultStyles: true,
      },
      experimental: {
        responsiveImages: true,
      },
    });

    After:

    export default defineConfig({
      image: {
        layout: 'constrained',
        objectFit: 'cover',
        objectPosition: 'center',
        breakpoints: [640, 750, 828, 1080, 1280],
        responsiveStyles: true, // This is now *false* by default
      },
    });

    Component usage remains the same

    The layout, fit, and position props on <Image> and <Picture> components work exactly the same as before:

    <Image
      src={myImage}
      alt="A responsive image"
      layout="constrained"
      fit="cover"
      position="center"
    />

    If you weren't using the experimental responsive images feature, no changes are required.

    Please see the Image guide for more information on using responsive images in Astro.

  • #13685 3c04c1f Thanks @ascorbic! - Adds experimental support for live content collections

    Live content collections are a new type of content collection that fetch their data at runtime rather than build time. This allows you to access frequently-updated data from CMSs, APIs, databases, or other sources using a unified API, without needing to rebuild your site when the data changes.

    Live collections vs build-time collections

    In Astro 5.0, the content layer API added support for adding diverse content sources to content collections. You can create loaders that fetch data from any source at build time, and then access it inside a page via getEntry() and getCollection(). The data is cached between builds, giving fast access and updates.

    However there is no method for updating the data store between builds, meaning any updates to the data need a full site deploy, even if the pages are rendered on-demand. This means that content collections are not suitable for pages that update frequently. Instead, today these pages tend to access the APIs directly in the frontmatter. This works, but leads to a lot of boilerplate, and means users don't benefit from the simple, unified API that content loaders offer. In most cases users tend to individually create loader libraries that they share between pages.

    Live content collections solve this problem by allowing you to create loaders that fetch data at runtime, rather than build time. This means that the data is always up-to-date, without needing to rebuild the site.

    How to use

    To enable live collections add the experimental.liveContentCollections flag to your astro.config.mjs file:

    {
      experimental: {
        liveContentCollections: true,
      },
    }

    Then create a new src/live.config.ts file (alongside your src/content.config.ts if you have one) to define your live collections with a live loader and optionally a schema using the new defineLiveCollection() function from the astro:content module.

    import { defineLiveCollection } from 'astro:content';
    import { storeLoader } from '@mystore/astro-loader';
    
    const products = defineLiveCollection({
      type: 'live',
      loader: storeLoader({
        apiKey: process.env.STORE_API_KEY,
        endpoint: 'https://api.mystore.com/v1',
      }),
    });
    
    export const collections = { products };

    You can then use the dedicated getLiveCollection() and getLiveEntry() functions to access your live data:

    ---
    import { getLiveCollection, getLiveEntry, render } from 'astro:content';
    
    // Get all products
    const { entries: allProducts, error } = await getLiveCollection('products');
    if (error) {
      // Handle error appropriately
      console.error(error.message);
    }
    
    // Get products with a filter (if supported by your loader)
    const { entries: electronics } = await getLiveCollection('products', { category: 'electronics' });
    
    // Get a single product by ID (string syntax)
    const { entry: product, error: productError } = await getLiveEntry('products', Astro.params.id);
    if (productError) {
      return Astro.redirect('/404');
    }
    
    // Get a single product with a custom query (if supported by your loader) using a filter object
    const { entry: productBySlug } = await getLiveEntry('products', { slug: Astro.params.slug });
    
    const { Content } = await render(product);
    ---
    
    <h1>{product.title}</h1>
    <Content />

    See [the docs for the experimental live content collections feature](https://docs.astro.build/en/reference/experimental-flags/live-content-c...

Read more

@astrojs/vercel@8.2.0

19 Jun 11:07
0ad80d9
Compare
Choose a tag to compare

Minor Changes

  • #13965 95ece06 Thanks @ematipico! - Adds support for the experimental static headers Astro feature.

    When the feature is enabled via option experimentalStaticHeaders, and experimental Content Security Policy is enabled, the adapter will generate Response headers for static pages, which allows support for CSP directives that are not supported inside a <meta> tag (e.g. frame-ancestors).

    import { defineConfig } from 'astro/config';
    import vercel from '@astrojs/vercel';
    
    export default defineConfig({
      adapter: vercel({
        experimentalStaticHeaders: true,
      }),
      experimental: {
        cps: true,
      },
    });

Patch Changes

  • #13917 e615216 Thanks @ascorbic! - The responsive images feature introduced behind a flag in v5.0.0 is no longer experimental and is available for general use.

    The new responsive images feature in Astro automatically generates optimized images for different screen sizes and resolutions, and applies the correct attributes to ensure that images are displayed correctly on all devices.

    Enable the image.responsiveStyles option in your Astro config. Then, set a layout attribute on any or component, or configure a default image.layout, for instantly responsive images with automatically generated srcset and sizes attributes based on the image's dimensions and the layout type.

    Displaying images correctly on the web can be challenging, and is one of the most common performance issues seen in sites. This new feature simplifies the most challenging part of the process: serving your site visitor an image optimized for their viewing experience, and for your website's performance.

    For full details, see the updated Image guide.

    Migration from Experimental Responsive Images

    The experimental.responsiveImages flag has been removed, and all experimental image configuration options have been renamed to their final names.

    If you were using the experimental responsive images feature, you'll need to update your configuration:

    Remove the experimental flag

    export default defineConfig({
       experimental: {
    -    responsiveImages: true,
       },
    });

    Update image configuration options

    During the experimental phase, default styles were applied automatically to responsive images. Now, you need to explicitly set the responsiveStyles option to true if you want these styles applied.

    export default defineConfig({
      image: {
    +    responsiveStyles: true,
      },
    });

    The experimental image configuration options have been renamed:

    Before:

    export default defineConfig({
      image: {
        experimentalLayout: 'constrained',
        experimentalObjectFit: 'cover',
        experimentalObjectPosition: 'center',
        experimentalBreakpoints: [640, 750, 828, 1080, 1280],
        experimentalDefaultStyles: true,
      },
      experimental: {
        responsiveImages: true,
      },
    });

    After:

    export default defineConfig({
      image: {
        layout: 'constrained',
        objectFit: 'cover',
        objectPosition: 'center',
        breakpoints: [640, 750, 828, 1080, 1280],
        responsiveStyles: true, // This is now *false* by default
      },
    });

    Component usage remains the same

    The layout, fit, and position props on <Image> and <Picture> components work exactly the same as before:

    <Image
      src={myImage}
      alt="A responsive image"
      layout="constrained"
      fit="cover"
      position="center"
    />

    If you weren't using the experimental responsive images feature, no changes are required.

    Please see the Image guide for more information on using responsive images in Astro.

  • Updated dependencies []:

    • @astrojs/underscore-redirects@1.0.0

@astrojs/cloudflare@12.6.0

19 Jun 11:07
0ad80d9
Compare
Choose a tag to compare

Minor Changes

  • #13837 7cef86f Thanks @alexanderniebuhr! - Adds new configuration options to allow you to set a custom workerEntryPoint for Cloudflare Workers. This is useful if you want to use features that require handlers (e.g. Durable Objects, Cloudflare Queues, Scheduled Invocations) not supported by the basic generic entry file.

    This feature is not supported when running the Astro dev server. However, you can run astro build followed by either wrangler deploy (to deploy it) or wrangler dev to preview it.

    The following example configures a custom entry file that registers a Durable Object and a queue handler:

    // astro.config.ts
    import cloudflare from '@astrojs/cloudflare';
    import { defineConfig } from 'astro/config';
    
    export default defineConfig({
      adapter: cloudflare({
        workerEntryPoint: {
          path: 'src/worker.ts',
          namedExports: ['MyDurableObject'],
        },
      }),
    });
    // src/worker.ts
    import type { SSRManifest } from 'astro';
    
    import { App } from 'astro/app';
    import { handle } from '@astrojs/cloudflare/handler';
    import { DurableObject } from 'cloudflare:workers';
    
    class MyDurableObject extends DurableObject<Env> {
      constructor(ctx: DurableObjectState, env: Env) {
        super(ctx, env);
      }
    }
    
    export function createExports(manifest: SSRManifest) {
      const app = new App(manifest);
      return {
        default: {
          async fetch(request, env, ctx) {
            await env.MY_QUEUE.send('log');
            return handle(manifest, app, request, env, ctx);
          },
          async queue(batch, _env) {
            let messages = JSON.stringify(batch.messages);
            console.log(`consumed from our queue: ${messages}`);
          },
        } satisfies ExportedHandler<Env>,
        MyDurableObject,
      };
    }

Patch Changes

  • #13963 c667c55 Thanks @florian-lefebvre! - Fixes a case where the platform proxy would not be disposed when the dev process ended

  • Updated dependencies []:

    • @astrojs/underscore-redirects@1.0.0

astro@5.9.4

17 Jun 08:39
a08c7e8
Compare
Choose a tag to compare

Patch Changes

  • #13951 7eb88f1 Thanks @ascorbic! - Fixes a issue that caused errors when using an adapter-provided session driver with custom options

  • #13953 448bddc Thanks @zaitovalisher! - Fixes a bug where quotes were not added to the 'strict-dynamic' CSP directive

@astrojs/underscore-redirects@1.0.0

17 Jun 08:39
a08c7e8
Compare
Choose a tag to compare

Major Changes

  • #13952 de82ef2 Thanks @ematipico! - - The type Redirects has been renamed to HostRoutes.

    • RouteDefinition.target is now optional
    • RouteDefinition.weight is now optional
    • Redirects.print has been removed. Now you need to pass Redirects type to the print function
    - redirects.print()
    + import { printAsRedirects } from "@astrojs/underscore-redirects"
    + printAsRedirects(redirects)

Minor Changes

  • #13952 de82ef2 Thanks @ematipico! - Adds a new method called createHostedRouteDefinition, which returns a HostRoute type from a IntegrationResolvedRoute.

  • #13952 de82ef2 Thanks @ematipico! - Adds a new method called printAsRedirects to print HostRoutes as redirects for the _redirects file.

@astrojs/netlify@6.4.0

17 Jun 08:39
a08c7e8
Compare
Choose a tag to compare

Minor Changes

  • #13952 de82ef2 Thanks @ematipico! - Adds support for the experimental static headers Astro feature.

    When the feature is enabled via option experimentalStaticHeaders, and experimental Content Security Policy is enabled, the adapter will generate Response headers for static pages, which allows support for CSP directives that are not supported inside a <meta> tag (e.g. frame-ancestors).

    import { defineConfig } from 'astro/config';
    import netlify from '@astrojs/netlify';
    
    export default defineConfig({
      adapter: netlify({
        experimentalStaticHeaders: true,
      }),
      experimental: {
        cps: true,
      },
    });

Patch Changes

@astrojs/cloudflare@12.5.5

17 Jun 08:39
a08c7e8
Compare
Choose a tag to compare

Patch Changes

astro@5.9.3

13 Jun 11:32
0644b40
Compare
Choose a tag to compare

Patch Changes

  • #13923 a9ac5ed Thanks @ematipico! - BREAKING CHANGE to the experimental Content Security Policy (CSP) only

    Changes the behavior of experimental Content Security Policy (CSP) to now serve hashes differently depending on whether or not a page is prerendered:

    • Via the <meta> element for static pages.
    • Via the Response header content-security-policy for on-demand rendered pages.

    This new strategy allows you to add CSP content that is not supported in a <meta> element (e.g. report-uri, frame-ancestors, and sandbox directives) to on-demand rendered pages.

    No change to your project code is required as this is an implementation detail. However, this will result in a different HTML output for pages that are rendered on demand. Please check your production site to verify that CSP is working as intended.

    To keep up to date with this developing feature, or to leave feedback, visit the CSP Roadmap proposal.

  • #13926 953a249 Thanks @ematipico! - Adds a new Astro Adapter Feature called experimentalStaticHeaders to allow your adapter to receive the Headers for rendered static pages.

    Adapters that enable support for this feature can access header values directly, affecting their handling of some Astro features such as Content Security Policy (CSP). For example, Astro will no longer serve the CSP <meta http-equiv="content-security-policy"> element in static pages to adapters with this support.

    Astro will serve the value of the header inside a map that can be retrieved from the hook astro:build:generated. Adapters can read this mapping and use their hosting headers capabilities to create a configuration file.

    A new field called experimentalRouteToHeaders will contain a map of Map<IntegrationResolvedRoute, Headers> where the Headers type contains the headers emitted by the rendered static route.

    To enable support for this experimental Astro Adapter Feature, add it to your adapterFeatures in your adapter config:

    // my-adapter.mjs
    export default function createIntegration() {
      return {
        name: '@example/my-adapter',
        hooks: {
          'astro:config:done': ({ setAdapter }) => {
            setAdapter({
              name: '@example/my-adapter',
              serverEntrypoint: '@example/my-adapter/server.js',
              adapterFeatures: {
                experimentalStaticHeaders: true,
              },
            });
          },
        },
      };
    }

    See the Adapter API docs for more information about providing adapter features.

  • #13697 af83b85 Thanks @benosmac! - Fixes issues with fallback route pattern matching when i18n.routing.fallbackType is rewrite.

    • Adds conditions for route matching in generatePath when building fallback routes and checking for existing translated pages

    Now for a route to be matched it needs to be inside a named [locale] folder. This fixes an issue where route.pattern.test() incorrectly matched dynamic routes, causing the page to be skipped.

    • Adds conditions for route matching in findRouteToRewrite

    Now the requested pathname must exist in route.distURL for a dynamic route to match. This fixes an issue where route.pattern.test() incorrectly matched dynamic routes, causing the build to fail.

  • #13924 1cd8c3b Thanks @qw-in! - Fixes an edge case where isPrerendered was incorrectly set to false for static redirects.

  • #13926 953a249 Thanks @ematipico! - Fixes an issue where the experimental CSP meta element wasn't placed in the <head> element as early as possible, causing these policies to not apply to styles and scripts that came before the meta element.

astro@5.9.2

09 Jun 15:32
4d96bda
Compare
Choose a tag to compare

Patch Changes

  • #13919 423fe60 Thanks @ematipico! - Fixes a bug where Astro added quotes to the CSP resources.

    Only certain resources require quotes (e.g. 'self' but not https://cdn.example.com), so Astro no longer adds quotes to any resources. You must now provide the quotes yourself for resources such as 'self' when necessary:

    export default defineConfig({
      experimental: {
        csp: {
          styleDirective: {
            resources: [
    -          "self",
    +          "'self'",
              "https://cdn.example.com"
            ]
          }
        }
      }
    })
  • #13914 76c5480 Thanks @ematipico! - BREAKING CHANGE to the experimental Content Security Policy feature only

    Removes support for experimental Content Security Policy (CSP) when using the <ClientRouter /> component for view transitions.

    It is no longer possible to enable experimental CSP while using Astro's view transitions. Support was already unstable with the <ClientRouter /> because CSP required making its underlying implementation asynchronous. This caused breaking changes for several users and therefore, this PR removes support completely.

    If you are currently using the component for view transitions, please remove the experimental CSP flag as they cannot be used together.

    import { defineConfig } from 'astro/config';
    
    export default defineConfig({
      experimental: {
    -   csp: true
       }
    });

    Alternatively, to continue using experimental CSP in your project, you can consider migrating to the browser native View Transition API and remove the <ClientRouter /> from your project. You may be able to achieve similar results if you are not using Astro's enhancements to the native View Transitions and Navigation APIs.

    Support might be reintroduced in future releases. You can follow this experimental feature's development in the CSP RFC.