You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a collection with a lexical editor. On my front-end I'm using the client-side useLivePreview() hook. It works great, except when using the upload feature in dev mode. I sometimes get this error when inserting an upload -- but most often when trying to drag/move an existing upload to a different position:
at eval (traverseRichText.js:47:89)
at Array.forEach (<anonymous>)
at traverseRichText (traverseRichText.js:34:35)
at eval (traverseRichText.js:14:20)
at Array.map (<anonymous>)
at traverseRichText (traverseRichText.js:10:31)
at eval (traverseRichText.js:59:31)
at Array.forEach (<anonymous>)
at traverseRichText (traverseRichText.js:34:35)
at eval (traverseRichText.js:59:31)
at Array.forEach (<anonymous>)
at traverseRichText (traverseRichText.js:34:35)
at eval (traverseFields.js:14:111)
at Array.forEach (<anonymous>)
at traverseFields (traverseFields.js:9:18)
at mergeData (mergeData.js:22:71)
at handleMessage (handleMessage.js:30:90)
at onMessage (subscribe.js:10:98)
Attempting to understand the issue, I made a small modification to the traverseRichText.js file. When making result.value conditional on line 42 the error will resolve:
const hasChanged = result && typeof result === 'object' && result.value?.id === externallyUpdatedRelationship?.id;
However, still curious why value would be empty, I threw a console log in on the line above:
It appears there is a problem with race conditions inside the traverseRichText.js with the the upload (and likely other features as well that rely on data from other collections), which causes it to fail when it runs before the data has been populated.
My "fix" above is thus likely a band-aid for the error rather than a solution for a bigger issue further up the functional chain.
It's worth noting that this doesn't happen (or at least hasn't happened to me yet) in the built app, I'm assuming because the data is populated fast enough that traverseRichText.js doesn't run before it's complete. However, the errors in dev mode point to an promise-related issue that probably needs to be resolved in any case and could still happen in production in the right (or, rather, wrong) server environment.
Install the repo (this is just a quick-and-dirty modification of beta 3.0 repo to set up live preview -- should work with any live preview using lexical editor w/ dev mode).
Create a new document, add an upload in the richText field along with some other content (in between a couple paragraphs, for example), save and open Live Preview.
Attempt to drag the upload node to a different location; error will likely appear in preview window's console and live preview will stop functioning.
Which area(s) are affected? (Select all that apply)
plugin: richtext-lexical, plugin: other
Environment Info
Binaries:
Node: 20.10.0
npm: 10.2.3
Yarn: N/A
pnpm: 9.7.1
Relevant Packages:
payload: 3.0.0-beta.124
next: 15.0.0
@payloadcms/db-mongodb: 3.0.0-beta.124
@payloadcms/db-postgres: 3.0.0-beta.124
@payloadcms/graphql: 3.0.0-beta.124
@payloadcms/live-preview: 3.0.0-beta.124
@payloadcms/live-preview-react: 3.0.0-beta.124
@payloadcms/next/utilities: 3.0.0-beta.124
@payloadcms/richtext-lexical: 3.0.0-beta.124
@payloadcms/richtext-slate: 3.0.0-beta.124
@payloadcms/translations: 3.0.0-beta.124
@payloadcms/ui/shared: 3.0.0-beta.124
react: 19.0.0-rc-65a56d0e-20241020
react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 10
The text was updated successfully, but these errors were encountered:
Describe the Bug
I have a collection with a lexical editor. On my front-end I'm using the client-side useLivePreview() hook. It works great, except when using the upload feature in dev mode. I sometimes get this error when inserting an upload -- but most often when trying to drag/move an existing upload to a different position:
Attempting to understand the issue, I made a small modification to the
traverseRichText.js
file. When making result.value conditional on line 42 the error will resolve:However, still curious why value would be empty, I threw a console log in on the line above:
Arg 2, the stringified output of my upload, was this:
whereas arg 3, the unstringified one, was:
It appears there is a problem with race conditions inside the
traverseRichText.js
with the the upload (and likely other features as well that rely on data from other collections), which causes it to fail when it runs before the data has been populated.My "fix" above is thus likely a band-aid for the error rather than a solution for a bigger issue further up the functional chain.
It's worth noting that this doesn't happen (or at least hasn't happened to me yet) in the built app, I'm assuming because the data is populated fast enough that
traverseRichText.js
doesn't run before it's complete. However, the errors in dev mode point to an promise-related issue that probably needs to be resolved in any case and could still happen in production in the right (or, rather, wrong) server environment.Link to the code that reproduces this issue
https://github.com/thoerr/payload-live-preview-error
Reproduction Steps
Which area(s) are affected? (Select all that apply)
plugin: richtext-lexical, plugin: other
Environment Info
The text was updated successfully, but these errors were encountered: