Skip to content
Compare
Choose a tag to compare
@astrobot-houston astrobot-houston released this 02 Aug 13:20
· 324 commits to main since this release
2abbc28

Patch Changes

  • #11584a65ffe3Thanks@bholmesdev!- Removes async local storage dependency from Astro Actions. This allows Actions to run in Cloudflare and Stackblitz without opt-in flags or other configuration.

    This also introduces a new convention for calling actions from server code. Instead of calling actions directly, you must wrap function calls with the newAstro.callAction()utility.

    callAction()is meant totriggeran action from server code.getActionResult()usage with form submissions remains unchanged.

    ---
    import{actions}from'astro:actions';
    
    constresult=awaitAstro.callAction(actions.searchPosts,{
    searchTerm:Astro.url.searchParams.get('search'),
    });
    ---
    
    {
    result.data&&
    {
    /*render the results*/
    }
    }

    Migration

    If you call actions directly from server code, update function calls to use theAstro.callAction()wrapper for pages andcontext.callAction()for endpoints:

    ---
    import { actions } from 'astro:actions';
    
    -const result = await actions.searchPosts({ searchTerm: 'test' });
    +const result = await Astro.callAction(actions.searchPosts, { searchTerm: 'test' });
    ---

    If you deploy with Cloudflare and addedthenodejs_compatornodejs_alsflagsfor Actions, we recommend removing these:

    compatibility_flags = [
    -"nodejs_compat",
    -"nodejs_als"
    ]

    You can also removenode:async_hooksfrom thevite.ssr.externaloption in yourastro.configfile:

    // astro.config.mjs
    import { defineConfig } from 'astro/config';
    
    export default defineConfig({
    -vite: {
    -ssr: {
    -external: [ "node:async_hooks" ]
    -}
    -}
    })