vuestorefront / storyblok

MOVED TO https://github.com/vuestorefront/vue-storefront/tree/legacy/packages/storyblok
https://docs.vuestorefront.io/storyblok/
12 stars 5 forks source link

Error in live preview "change" event #13

Open frans-vectra opened 3 years ago

frans-vectra commented 3 years ago

Hi, it seems like the handling of the change event in the storyblokBridge live preview is causing the following error:

storyblokBridge.js?3678:15 Uncaught TypeError: Cannot read properties of undefined (reading 'content')
    at m.eval (storyblokBridge.js?3678:15)
    at m.emit (storyblok-v2-latest.js:1)
    at m.receiveMessageFromApp (storyblok-v2-latest.js:1)

Upon further investigation it seems like the error happens when trying to access the payload.story.content property during the handling of the change event.

const storyblokBridge = (
  content = { content: {} },
  events = ['change', 'input'],
  relations = [],
) => {
  if (window) {
    // eslint-disable-next-line
    const instance = new StoryblokBridge({
      resolveRelations: relations,
    })
    instance.on(events, (payload) => {
      content.content = {
        ...payload.story.content, // <--- HERE
        _meta: payload.story,
      }
    })
  }
}

According to the Storyblok event docs the change event only has the following properties:

{
  "reload": true,
  "action": "change", // or published
  "slug": "home",
  "storyId": 24840769,
  "slugChanged": true
}

Not sure what the fix would be for this, the change event should probably be handled in a different way.

lukasborawski commented 3 years ago

@frans-vectra thanks for sharing this issue. We will check this one this or next week. Cheers.

bootsmann1995 commented 2 years ago

@lukasborawski was this fixed? i get this error.

frans-vectra commented 2 years ago

@bootsmann1995 I don't think so, I ended up switching to @storyblok/nuxt-2 for my Vue Storefront projects.