storyblok / storyblok-astro

Astro SDK for Storyblok CMS
161 stars 29 forks source link

script for `loadStoryblokBridge` is injected twice #943

Open oddcelot opened 1 day ago

oddcelot commented 1 day ago

Describe the issue you're facing

I was trying out the storyblok integration for astro (with v5 beta) as was noticing this warning in the console:

[!caution] Uncaught SyntaxError: Identifier 'loadStoryblokBridge' has already been declared (at page.js:14:24)

During dev this not an issue, but when building an error gets also thrown:

[!caution]

astro:scripts/page.js (14:23): Identifier "loadStoryblokBridge" has already been declared
file: astro:scripts/page.js:14:23

12:             
13: 
14:               import { loadStoryblokBridge, syncContentUpdate } from "@storyblok/astro";
                          ^
15:               loadStoryblokBridge().then(() => {
16:                 const { StoryblokBridge } = window;

 Hint:
   Browser APIs are not available on the server.

   If the code is in a framework component, try to access these objects after rendering using lifecycle methods or use a `client:only` directive to make the component exclusively run on the client.

   See https://docs.astro.build/en/guides/troubleshooting/#document-or-window-is-not-defined for more information.

It seems like this is related to this section: https://github.com/storyblok/storyblok-astro/blob/c555207a9b93989655431a95c57e5d7ab762f628/lib/index.ts#L193-L226

But looking at the config it seems fine and in line with the flow control here, so no idea why the script is injected both times, unless the resolved config is somehow different.

Reproduction

https://github.com/oddcelot/astro-storyblok

Steps to reproduce

No response

System Info

"@storyblok/astro": "5.1.0-alpha.4",
"astro": "5.0.0-beta.3"

Used Package Manager

pnpm

Error logs (Optional)

No response

Validations

oddcelot commented 1 day ago

So i did try and patch this via pnpm patch and removing the additonal import seems to resolve the issues for dev and build 🎉 https://github.com/oddcelot/astro-storyblok/commit/73855c864b048120704a8c1da372213b90bacdb7