Skip to content

Editing a File crashes the edit route: "Cannot read properties of undefined (reading '__somersault__')" #131

@mliebischer

Description

@mliebischer

Problem

Opening @@edit for a File content object (e.g. uploaded through Aurora) crashes with the error boundary:

TypeError: Cannot read properties of undefined (reading '__somersault__')
    at get$1 (…/dist-….js:178:62)
    at getValueUsingOptic (…/dist-….js:413:19)
    at Object.read (…/dist-….js:402:86)
    at atomRead (…/vanilla-….js:57:50)

Steps to reproduce

  1. Upload a file (e.g. via @@contents upload).
  2. Open @@edit on the uploaded File.
  3. The route crashes with the error above.

Analysis so far

  • The stack points at jotai-optics: packages/cmsui/routes/atoms.ts focuses the form atom with optic.prop('blocks').prop(id).
  • A File has no blocks field (the type does not use the blocks behavior), so the optic reads undefined, and the subsequent access to the Somersault block key (SOMERSAULT_KEY = '__somersault__', packages/plate/constants.ts) throws.
  • In other words: the edit route currently assumes blocks-enabled content. Any type without the blocks behavior is likely affected (e.g. Image as well).
  • Prior art: Volto renders a plain schema-driven form for such types and only mounts the blocks editor when the content has the blocks behavior.

Expected behavior

@@edit works for content types without the blocks behavior, rendering the schema fields without the Somersault editor (or with a guarded, empty editor state).

References

  • packages/cmsui/routes/atoms.ts (blocks optic)
  • packages/plate/constants.ts (SOMERSAULT_KEY)

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions