github withastro/astro astro@1.4.0

latest releases: astro@4.15.8, @astrojs/mdx@3.1.7, astro@4.15.7...
24 months ago

Minor Changes

  • #4907 01c1aaa00 Thanks @matthewp! - Order Astro styles last, to override imported styles

    This fixes CSS ordering so that imported styles are placed higher than page/component level styles. This means that if you do:

    ---
    import '../styles/global.css';
    ---
    
    <style>
      body {
        background: limegreen;
      }
    </style>

    The <style> defined in this component will be placed below the imported CSS. When compiled for production this will result in something like this:

    /* /src/styles/global.css */
    body {
      background: blue;
    }
    
    /* /src/pages/index.astro */
    body:where(.astro-12345) {
      background: limegreen;
    }

    Given Astro's 0-specificity hashing, this change effectively makes it so that Astro styles "win" when they have the same specificity as global styles.

  • #4876 d3091f89e Thanks @matthewp! - Adds the Astro.cookies API

    Astro.cookies is a new API for manipulating cookies in Astro components and API routes.

    In Astro components, the new Astro.cookies object is a map-like object that allows you to get, set, delete, and check for a cookie's existence (has):

    ---
    type Prefs = {
      darkMode: boolean;
    };
    
    Astro.cookies.set<Prefs>(
      'prefs',
      { darkMode: true },
      {
        expires: '1 month',
      }
    );
    
    const prefs = Astro.cookies.get<Prefs>('prefs').json();
    ---
    
    <body data-theme={prefs.darkMode ? 'dark' : 'light'}></body>

    Once you've set a cookie with Astro.cookies it will automatically be included in the outgoing response.

    This API is also available with the same functionality in API routes:

    export function post({ cookies }) {
      cookies.set('loggedIn', false);
    
      return new Response(null, {
        status: 302,
        headers: {
          Location: '/login',
        },
      });
    }

    See the RFC to learn more.

Patch Changes

Don't miss a new astro release

NewReleases is sending notifications on new releases.