storyblok / storyblok-astro

Astro SDK for Storyblok CMS
MIT License
163 stars 29 forks source link

ALL the registered bloks are loaded on the client even when not used on the current page #886

Open Dav3rs opened 4 months ago

Dav3rs commented 4 months ago

Describe the issue you're facing

I notice that my page was crashing due to scripts being executed that have nothing to do with the current page content.

It looks that ALL the storyblok components registered in the project are sent to client even when they are not needed in the current page consumed stories.

For example

1- I create a component that is not used on the page image

2- With the next content image

3- It it loaded :face_with_diagonal_mouth: image

Reproduction

https://stackblitz.com/~/github.com/Dav3rs/astro-storyblok

Steps to reproduce

No response

System Info

Linux, astro latest, node lts.

Used Package Manager

npm

Error logs (Optional)

No response

Validations

mediabeastnz commented 3 months ago

I'm seeing the same thing, even on deployed sites astro build.

I'd put this high on the priority list as it could definitely effect performance and cause had to debug issues.

mediabeastnz commented 3 months ago

After looking into this more it looks like this is expected behaviour from Astro. any script tags are automatically hoisted and loaded as JS modules.

A workaround if this causes issues I guess is to have the script inline or add attributes to the script tag.

Dav3rs commented 3 months ago

@manuelschroederdev This is a huge flaw of the astro integration, it should be prioritized don't you think so?

dipankarmaikap commented 3 months ago

@Dav3rs , Thank you for bringing this issue to our attention. We're actively investigating it and will keep you updated with our findings. If we identify any workarounds or solutions, we’ll share them with you here and document them for other users as well.

markpinero commented 3 months ago

There’s no way to integrate dynamic components without a change in how Astro changes their build process. Related discussion: https://github.com/withastro/astro/issues/4863

moritzlaube commented 1 week ago

We have opened an issue quite a while ago that is discussing the exact same problem. Just to get everyone on the same page: https://github.com/withastro/astro/issues/4863#issuecomment-2472642951

And I still think it is a crucial thing, especially when working with a CMS.

moritzlaube commented 1 week ago

Sorry @markpinero, I just saw that you were referring to it already.

moritzlaube commented 1 week ago

Hi everyone! I've started a discussion about tree-shaking unnecessary components for static builds with CMS page builders here: https://github.com/withastro/roadmap/discussions/1054

Would love to hear your thoughts! My knowledge is clearly limited, so please weigh in.