Closed mandalornl closed 1 year ago
Hi @mandalornl,
the v-editable
is not designed or expected to work with statically generated sites. It is exclusively to be used for preview environments.
I'm not sure why you would want to use it in a production environment that is not viewed in Visual Editor and thus requires no interactivity with the Storyblok Bridge. Could you please elaborate? 🙂
@manuelschroederdev Our production environment uses static pages exclusively to host our projects, but we make use of Nuxt preview mode to enable the Storyblok Bridge and use the draft
version on all API calls. This happens only when viewed in the Visual Editor. However, when pages are generated during our CI/CD pipeline, the published
version is used (for obvious reasons) and the _editable
property is missing from the API response (also for obvious reasons). Therefore, the data-blok-c
attribute is updated only if the update
directive event is also triggered in preview mode. Then click events will work as expected when viewed in the Visual Editor.
I hope this clarifies the issue.
@mandalornl I understand. I'd suggest using two completely separate environments. One using the preview access token, fetching draft stories, and running nuxt build
, the other one using the public access token, fetching published stories, and running nuxt generate
.
You could set this up as two projects in Vercel/Netlify/whatever you're using, using the same code base and repository, just differentiating via environment variables.
@manuelschroederdev I decided to abandon @storyblok/nuxt-2
and opted to manually initialize loadStoryblokBridge
and useStoryblokBridge
from @storyblok/js
when in preview mode. I also implemented my own Editable
directive to handle bind
and update
events. It seems to work just fine now for our use case.
Thank you for your time :slightly_smiling_face:
Describe the issue you're facing
I'm getting an error when I try to click on a component with
v-editable
enabled and I'm having trouble getting it to work properly with@storyblok/nuxt-2
and statically generated pages.I believe it is related to
v-editable
not being triggered by theupdate
event. Currently it only listens to thebind
event, so it will only trigger when the component is created.https://github.com/storyblok/storyblok-vue-2/blob/3ab1e43647e34b524d3cf62fed03d2dd1f45ce65/lib/src/index.ts#L16
We use
nuxt generate
to generate static pages for our projects. Because it is not being viewed in theVisual Editor
at the time of generation and thepublished
version is requested, thebind
event will of course not detect the_editable
property in thestory.content
API response. I therefore think the directive should listen to both thebind
andupdate
events. This way, when the static page is visited on the client from inside the editor, theupdate
event will be fired and thedata-blok-c
attribute will be updated accordingly to fix the problem.I was able to get it to work with the code snippet below.
Just to rule out. I'm using the
draft
version when viewed in the editor and I'm using thepreview
API key.Reproduction
n/a
Steps to reproduce
nuxt generate
.Visual Editor
and click on any component withv-editable
enabled.System Info
Used Package Manager
yarn
Error logs (Optional)
No response
Validations