-
Notifications
You must be signed in to change notification settings - Fork 46
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
await useStoryblok() in NUXT 3 setup script does NOT actually await (RESOLVED) #155
Comments
I'm having the same issue. I would expect it to be rendered on the server side. |
Have you checked if it is also requested on the server side? Because 2 have two requests. |
I can confirm the same issue with I think the issue is with the @danielmalmros can you confirm that you are also seeing the same behaviour if you display the content with |
UPDATEWe got it resolved:
We overwrote with this
More info: https://v3.nuxtjs.org/guide/directory-structure/components/#dynamic-components |
@nedas-dev Holy shit thats a good workaround! Thanks for that fix! Since mine is in a v-for I did it as follows:
|
Thanks, that helped me a lot as well. <script setup>
const story = await useStoryblok('home', { version: 'draft', });
const component = resolveComponent(story.value.content.component)
</script> |
Hi @nedas-dev @danielmalmros @marcohofmann @SebbeJohansson @mario-neuhold I know it's been a long time since this issue, but have you seen the new composable that makes use of Nuxt's Let me know if everything is ok nowadays, to close the issue, or if you need anything else! |
Edit: I think I was confused back in november. |
Edit: I think I was confused back in november. |
Edit: I think I was confused back in november. |
Keep in mind that this issue is not only with async, but also with the normal useStoryblok composable. |
I do honestly believe this problem still exists. Well, at least for me, it does. I've upgraded Node, tried all the workaround, and it's only fine when The bigger shame with the whole thing is its erratic nature. It would load fine sometimes and then would suddenly break, or sometimes just outright return 500 and, of course, that breaks everything. Here's a link to my project (open), if anyone wants to take a look, and especially if I'm really goofing somewhere and woefully blinded to it myself ==> https://gitlab.com/k16e/c.food Thanks. |
@k16e-me not sure why yours isnt waiting for the result. might be something with how you store the result or that the slug is incorrect. This issue is specifically for the fact that before the storyblok components didn't render at all on ssr, which I know for a fact yours does. I think you should open a new issue for the other stuff! |
Hi @k16e-me could you please confirm for me if the bug is still happening to prioritize? Thank you |
@alvarosabu @k16e-me I believe this is still happening for me too but I have noticed something that might help -- I'm not sure if this is actually a problem with the Storyblok plugin (at least in my case) or if it's a Nuxt SSG/Vue Router problem. I just started building a site and I'd really prefer to be full static delivery and not hit Storyblok at all. This is my first Nuxt 3 (built a few with Nuxt 2) site and second Storyblok site (the other used Astro). After running Because I was only seeing it sometimes, I spent some time clicking around and reloading trying to find a pattern. It looks like it's because of trailing slashes. My
While navigating the site using those links everything's fine. But if I reload while looking at any route that's not the homepage, for example I've tried forcing trailing slashes off using various Nuxt configs and middlware with no success (I'd prefer not to have trailing slashes). The only solution I found was to add trailing slashes to my links so that when Nuxt prerenders the site, it creates matching pages. Then if I reload, there's a matching static file for that route. This still leaves an issue if someone hits a link that doesn't include a trailing slash (for example saying to someone "go to website.com slash trial" they're going to type in website.com/trial with no trailing slash. So I still need to find a way to force it entirely one way or the other, although I'm not sure if that's even possible with SSG. I might need a CloudFlare redirect rule. And I need to figure out why trailing slashes are being added in the first place and turn that off. It must be Nuxt/Vue Router doing it since it happens both in CloudFlare and locally using I found a discussion here which exactly describes what I'm seeing, but none of the proposed solutions seemed to work for me. And neither did any of the ones in this SO thread. Also just found this discussion, seems like this is a known issue with work in progress: nuxt/nuxt#15462 (comment) |
@thomascallahan doing fully static has always been hard, but I have an example where I have gotten it to work, but not with the composables. I have a plan to look into this more, but life has gotten between those plans. Here is a production url: https://sebbejohansson.com/blog/performance-improvements/ This should allow for properly pre generated pages. Alba at storyblok has plans to incorporate something similar into UseAsyncStoryblok so that should be possible to use instead. |
@SebbeJohansson Thanks for all of that. I tried a version of that in my project (had to modify it a little) and like other solutions I tried, I think I made a mistake trying Nuxt 3, seems like SSG is just not ready in it yet, or at least not when combined with Storyblok. As much as I don't want to do this (I really don't like React or JSX) I may have to give up and use NextJS, I've had no problems generating truly static sites with it. Or maybe fall back to Nuxt 2 for now. |
@thomascallahan nuxt3 with ssg works fine, so sounds like something is wrong in your version. Feel free to message me on discord and I'll see if I can help you. |
I found the reason and a solution. useStoryblokBridge is in fact the problem and causes payload invalidation and reloading, instead of relying on the pre-generated payload. To fix, instead of using useAsyncStoryblok, just fetch the story manually with useAsyncData and storyblokApi.get (as shown in readme). Then, to have the bridge when actually editing in the visual editor, add this onMounted code:
|
@SebbeJohansson Did you notice? But then, @danbaechtold would you be able to show how Because even if your solution works, it's like going back where we're supposed to move away from. If Storyblok has written a shorthand that wraps up the manual process, going back to that feels like overwork/repeat code. |
@danbaechtold can you confirm that you have the same issue when running useAsyncStoryblok? Could have sworn this works now. |
Yes, my solution is a workaround and I'd also prever to be able to use "useAsyncStoryblok". I was able to reproduce it in a new nuxt app and to find the exact cause: It's only breaking when I use different "version" parameters based on NODE_ENV. So, with this: And then running "nuxt generate" and "nuxt preview, "useAsyncStoryblok" will fail, while my workaround will still work. It must be the bridge. Here is a simple Repro: |
This makes a lot of sense. Would a rewrite be something Nuxt 3 is involved or is it solely from the Storyblok module end? |
@danbaechtold I still dont understand why some people want to fetch version based on Edit: Looking at your code, it seems like the main difference is the use of |
Previews without needing Storyblok access. I have stakeholders who needs one-time access to review draft content, or they forward those requests get forwarded to different people, and I can't reasonably provision Storyblok access for each of them. And others who need routine access so they might warrant user provisioning, but I can't imagine being able to get them to log in to Storyblok -- think execs who just want to be able to see the site without knowing anything at all about how it's built. (Security of the draft content is not an issue in my case). I have a preview version of a site deployed in SPA mode on CloudFlare Pages so that content stakeholders can see the draft content without having to have Storyblok access. This is the same site I use for Storyblok's editor preview for content authors, but because it can be accessed outside of Storyblok and I want them to be able to navigate around the site normally while remaining in draft content mode, it has to be set in the build config rather than detecting if it's running in the editor or not at runtime. And then production deployment is a second CF Pages site that does a static build from a Storyblok webhook instead of SPA. I suppose I could dynamically detect if it's running in the editor AND check the domain in order to set this at runtime, but to me it was just easier to set an environment variable in CF Pages -- it's an environment detail. I'm actually just setting the content version name as an environment variable, like |
@thomascallahan getting close to being off topic for this issue, but that makes so much sense. I've not needed that yet, but I do see that use case being a thing. I personally would rather put a cookie if needing to preview consistantly accross a site tho. |
@SebbeJohansson No, it is not the toRef that solves the problem, but the condition around "useStoryblokBridge":
If the condition is removed, it breaks. The error then is: PS, my reason to use NODE_ENV is that I like to develop new features outside of the editor. But if I then have for example to add a new Blok I'm developing, then obiously I need to add it to the (draft) content and prefer not to have to publish yet. Developing outside of the editor is easier in terms of space, dev tools, etc. |
I will close this issue since people already help each other. If you have any problems with this topic, please create a new issue with a reproducible example. For now, you can check the latest changes to the composable at #398. Please let me know your opinions and use cases from your side <3 Thanks for helping each other. I loved reading the thread and seeing people helping! |
Hey guys, I have this issue - once I build and run nuxt 3 in
production environment
,await useStoryblok('home', { version: 'draft', });
does not actually await for the content, it gets rendered on client side only. And yes -ssr:true
.All other pages that retrieve from, let's say Shopify GraphQL API, does await and load content on server side.
Any ideas?
index.vue
This is my package.json
The text was updated successfully, but these errors were encountered: