sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.28k stars 426 forks source link

Presentation crashes on newest versions: Failed to execute 'postMessage' on 'Window' #7689

Open dagstuan opened 2 weeks ago

dagstuan commented 2 weeks ago

Describe the bug

I'm using Sanity with Next.js 14. I have set up visual editing using the documentation, after upgrading the packages to the newest versions, the Presentation tool crashes with the following error

raise-5ea71f04.development.esm.js:126 Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': Symbol(react.forward_ref) could not be cloned.
    at eval (PresentationToolGrantsCheck.js:400:1)
    at Set.forEach (<anonymous>)
    at sendAsChannelsMessage (PresentationToolGrantsCheck.js:399:1)
    at executeAction (raise-5ea71f04.development.esm.js:2305:1)
    at resolveAndExecuteActionsWithContext (raise-5ea71f04.development.esm.js:2312:1)
    at resolveActionsAndContext (raise-5ea71f04.development.esm.js:2343:1)
    at enterStates (raise-5ea71f04.development.esm.js:2121:1)
    at microstep (raise-5ea71f04.development.esm.js:2065:1)
    at macrostep (raise-5ea71f04.development.esm.js:2402:1)
    at StateMachine.transition (xstate.development.esm.js:426:21)
    at Actor._process (raise-5ea71f04.development.esm.js:834:1)
    at Mailbox.flush (raise-5ea71f04.development.esm.js:43:1)
    at Mailbox.enqueue (raise-5ea71f04.development.esm.js:35:1)
    at Actor._send (raise-5ea71f04.development.esm.js:956:1)
    at Object._relay (raise-5ea71f04.development.esm.js:395:1)
    at eval (raise-5ea71f04.development.esm.js:318:1)

After the crash I receive a lot of warnings in the console like:

Event "post" was sent to stopped actor "x:4 (x:4)". This actor has already reached its final state, and will not transition.
Event: {"type":"post","data":{"type":"comlink/heartbeat"}}

I have traced the error back to [@sanity/visual-editing@2.2.0] which introduces comlink for messaging. If I downgrade that package to 2.1.9 and then downgrade all the other packages to match, everything starts working again.

To Reproduce

It's hard to say how to reproduce. I have another solution that works fine, but the one I'm working on now crashes. So it might be related to my code/dataset somehow. But I haven't changed any of my own code apart from upgrading packages.

Expected behavior

No crash.

Screenshots

image

Which versions of Sanity are you using?

@sanity/code-input 4.1.4 (up to date) @sanity/image-url 1.0.2 (up to date) @sanity/orderable-document-list 1.2.2 (up to date) @sanity/preview-url-secret 2.0.0 (up to date) @sanity/react-loader 1.10.14 (up to date) @sanity/ui 2.8.10 (up to date) @sanity/vision 3.62.2 (up to date) sanity 3.62.2 (up to date)

What operating system are you using?

Mac OS Sonoma 14.6.1

dagstuan commented 2 weeks ago

Amazingly, this seems to be related to using react-components as media previews for documents. If I remove all references to react-components from my schema type previews, everything works correctly. But a setup such as the one below yields an error:

image image

But the following setup works fine:

image
ragnsan commented 2 weeks ago

I also had the same problem. Though I had the key icon in the prepare() function for a schema preview (oops). But same scenario as @dagstuan with having JSX components inside of the preview settings for a schema definition.

stipsan commented 1 week ago

Thanks for reporting! We'll look into this next week 🙌

oskarengstrom commented 1 week ago

Following. Also noticed that the issue started when moving from 3.61.0 to 3.62.0.