Skip to content

🐛 [Bug]: useStoryblokApi() in Astro Cloudflare Workers SSR environment causes request hangs/crashes #533

@nonsponsored

Description

@nonsponsored

Package

@storyblok/astro (Astro Integration)

Bug Description

When useStoryblokApi() is used in Astro SSR request paths running on Cloudflare Workers, navigation can eventually cause requests to hang and the Worker to fail. In testing, replacing those server-side useStoryblokApi() calls with plain fetch() calls to the Storyblok CDN endpoints stopped the crashes. The issue reproduces locally with astro dev + @astrojs/cloudflare and on a deployed Cloudflare Worker. It has been confirmed and replicated in both Chrome and Safari.

Steps to Reproduce

  1. Clone the repro project: https://github.com/nonsponsored/bug-astro-ssr-cloudflare-workers-storyblok
  2. Add a .env file with:
  • STORYBLOK_API_KEY=<preview token>
  • STORYBLOK_API_VERSION=draft
  • STORYBLOK_REGION=<us or eu>
  1. Install dependencies and run the project:
    npm install
    npm run dev
  2. Open the repo in a browser.
  3. Repeat clicking back and forth between:
  • /sdk-space
  • /sdk-links
  1. Continue navigating until the Worker fails.
  2. Optionally repeat the same test on a deployed Cloudflare Worker build.

Expected Behavior

SSR navigation using useStoryblokApi() should continue to work without hanging, suspending the Worker, or throwing a runtime exception.

Actual Behavior

After repeated navigation, the Worker eventually fails. In the full application this could happen after roughly 5 navigations on content-heavy pages; in the minimal repro it can take around 20–30 clicks.
Observed failures include:

  • Cloudflare Worker error: The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response
  • Cloudflare error page / Worker exception (1101)
  • In local dev, repeated WebSocket is closed due to suspension messages and eventual request failure

Code Sample

Environment

System:
  OS: macOS 15.7.4
  CPU: (8) arm64 Apple M3
  Memory: 94.33 MB / 24.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.22.1
  npm: 10.9.4
  pnpm: 10.28.1
Browsers:
  Brave Browser: 146.1.88.136
  Chrome: 146.0.7680.155
  Firefox: 148.0.2
  Safari: 26.3
  Safari Technology Preview: 26.0
npmPackages:
  @storyblok/astro: ^9.0.0 => 9.0.0 
  astro: ^6.0.8 => 6.0.8

Error Logs

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions