Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Error in live preview "change" event #13

Open
frans-vectra opened this issue Nov 10, 2021 · 3 comments
Open

Error in live preview "change" event #13

frans-vectra opened this issue Nov 10, 2021 · 3 comments

Comments

@frans-vectra
Copy link

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
Copy link
Collaborator

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

@bootsmann1995
Copy link

@lukasborawski was this fixed? i get this error.

@frans-vectra
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants