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

Error in live preview "change" event #13

@frans-vectra

Description

@frans-vectra

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions