Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storyblok client throttling crashing Astro adapter in CloudFlare Worker #682

Open
Soviut opened this issue Nov 14, 2023 · 14 comments · May be fixed by #865
Open

Storyblok client throttling crashing Astro adapter in CloudFlare Worker #682

Soviut opened this issue Nov 14, 2023 · 14 comments · May be fixed by #865
Assignees
Labels
has-workaround [Issue] Temporary solutions available. pending-triage [Issue] Ticket is pending to be prioritised

Comments

@Soviut
Copy link

Soviut commented Nov 14, 2023

I have a project using Astro. Astro has a CloudFlare Worker "adapter" for doing server side rendering (SSR). This will re-render the preview page every time someone hits "save" in the Storyblok editor.

However, after several consecutive saves, the worker eventually crashes, giving a "The script will never generate a response" error.

Based on the comment in this thread, it seems to be caused by throttling in the Storyblok client not resolving all its promises and therefore never returning a result. withastro/adapters#43 (comment)

They include links to the code in question as well as some workaround code to monkey patch the Storyblok client.


Expected Behavior

I should be able to save frequently without the Storyblok client failing.

Current Behavior

Saving frequently causes the client to eventually fail, crashing the worker.

Steps to Reproduce

The author of the original thread provided a Stackblitz to reproduce https://stackblitz.com/edit/github-tkyzda-4d7fjz?file=astro.config.mjs

  1. Create an Astro project
  2. Install the CloudFlare adapter for Astro
  3. Follow this tutorial to create a generateStaticPaths function for Astro that calls Storyblok https://www.storyblok.com/tp/create-a-preview-environment-for-your-astro-website
  4. Deploy to CloudFlare
  5. Point Storyblok editor at cloudflare URL
  6. Make content changes and save them quickly
  7. Observe the cloudflare worker eventually return an error
@thiagosaife
Copy link

We'll address this one.

@grantlucas
Copy link

I was happy to find this reported issue after going down the exact same path as the original reporter with the exact same set of tools. Is there any estimation on a potential fix for this? Thank you

@patrick-schneider-latori

@thiagosaife Any updates on this one? We currently omit the client (and created our own fetcher), since it makes all our production sites crash...this should not be the case!

@Soviut
Copy link
Author

Soviut commented Feb 3, 2024

@patrick-schneider-latori it would be good if you could post your solution or even make a PR with your changes.

@F0rce
Copy link

F0rce commented Feb 6, 2024

Is there any way to prioritise this? Like some other commenters, we have fallen down this rabbit hole and have not been able to sort it out, before finding this issue.

@negprof
Copy link

negprof commented Mar 13, 2024

Also the same problem with this using hydrogen shopify.

@jansvabik
Copy link

I have to admit that I've been eagerly waiting for a solution to this problem for months, like many of you. Today, I decided to dive deeper into the code of both this repository and the @storyblok/astro repository to see if I could contribute a solution myself. To my surprise, I discovered that we can adjust the rateLimit parameter in the apiOptions within our astro.config.mjs config. By default, it's set to 5 requests, but adjusting it can significantly impact how the client behaves under heavy load. Here's a quick example of how you can adjust this in your config:

// in your astro.config.mjs
// ...
storyblok({
    accessToken: env.STORYBLOK_TOKEN,
    apiOptions: {
        // ...
        rateLimit: 250,
        // ... 
    },
    // ...
})
// ...

I hope this solution helps others who are encountering the same issue. If anyone has further insights or alternative solutions, I encourage you to share them with the community. 🙂

@remi-freriks
Copy link

We have the same problem with Cloudflare Workers. Even with rateLimit at 250. Is Storyblok still working on this problem?

@alvarosabu alvarosabu added the pending-triage [Issue] Ticket is pending to be prioritised label Aug 21, 2024
@alvarosabu
Copy link
Contributor

Hi @remi-freriks let me discuss it internally.

@patrick-schneider-latori

I really hope you find a final solution now @alvarosabu – this problem exists since months and your module is unusable for Cloudflare users.

@patrick-schneider-latori
Copy link

patrick-schneider-latori commented Aug 30, 2024

@patrick-schneider-latori it would be good if you could post your solution or even make a PR with your changes.

@Soviut we are just using simple url fetch. no rocket science involved. But it gives a lot of pain and manual adjustments involved when you want to integrate this in Typescript...

@alvarosabu alvarosabu added the has-workaround [Issue] Temporary solutions available. label Sep 17, 2024
@alvarosabu
Copy link
Contributor

Hi @patrick-schneider-latori did you try this workaround suggested here #682 (comment) ?

@alvarosabu alvarosabu self-assigned this Sep 17, 2024
@patrick-schneider-latori

Hi @patrick-schneider-latori did you try this workaround suggested here #682 (comment) ?

Hi @alvarosabu – no, we did not, since we need a robust and working solution for our customers, which all have high traffic. And according to what @remi-freriks it also does not make me happy. Therefore we still stick with native fetch and url parameters, since this solution is also compatible with Cloudflare caching and battle-tested on high traffic websites.

@alvarosabu
Copy link
Contributor

Hi @patrick-schneider-latori thanks for getting back, that made absolute sense, let me get it to the team to prioritize it and hopefully work on it soon.

Thanks for the patience

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-workaround [Issue] Temporary solutions available. pending-triage [Issue] Ticket is pending to be prioritised
Projects
None yet
9 participants