Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical] temporarily set editor to not writable when calling getCachedTypeToNodeMap #7022

Closed
wants to merge 4 commits into from

Conversation

potatowagon
Copy link
Contributor

Description

Describe the changes in this pull request

Closes #

Test plan

Before

Insert relevant screenshots/recordings/automated-tests

After

Insert relevant screenshots/recordings/automated-tests

Copy link

vercel bot commented Jan 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 4:30pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 4:30pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 7, 2025
@potatowagon potatowagon marked this pull request as draft January 7, 2025 16:17
Copy link

github-actions bot commented Jan 7, 2025

size-limit report 📦

Path Size
lexical - cjs 31.39 KB (0%)
lexical - esm 31.19 KB (0%)
@lexical/rich-text - cjs 40.47 KB (0%)
@lexical/rich-text - esm 33.12 KB (0%)
@lexical/plain-text - cjs 39.04 KB (0%)
@lexical/plain-text - esm 30.37 KB (0%)
@lexical/react - cjs 42.3 KB (0%)
@lexical/react - esm 34.42 KB (0%)

@etrepum
Copy link
Collaborator

etrepum commented Jan 7, 2025

This doesn’t seem like the right thing to do, and would cause extra events to fire, what are the preconditions for this problem?

@potatowagon
Copy link
Contributor Author

This doesn’t seem like the right thing to do, and would cause extra events to fire, what are the preconditions for this problem?

im not sure what other side effects this would introduce, trying it out in a draft PR to experiment, so happy to close if this PR will cause nasty side effects.

this is a followup to the breaking change in #6894. one trigger is a case of editor.registerNodeTransform being called from a useEffect in workplace. that cause workplace post composer to break. i fixed it on the intergration layer, but not sure where else could break as a result of getCachedTypeToNodeMap being called with a writable editor state

@potatowagon
Copy link
Contributor Author

and would cause extra events to fire

this looks correct based on the unit tests failures

@etrepum
Copy link
Collaborator

etrepum commented Jan 7, 2025

This should only be a problem if getEditorState returns a writable state, it’s never supposed to, because that is the state that was most recently reconciled. There is a workaround in there to handle an initial empty EditorState which is not frozen, but maybe there is also a case where your team is creating a non-empty EditorState that is not frozen but still returned from getEditorState somehow? I’m not currently at a computer to look into this but if you can come up with a repro I’m sure we can fix this cleanly

@etrepum
Copy link
Collaborator

etrepum commented Jan 7, 2025

In this scenario what I would do, if I couldn't diagnose and fix the root cause of editor.getEditorState() returning a non-empty writable EditorState under some condition, is expose computeTypeToNodeMap and call that instead when this issue would trigger. You really don't want to populate this cache with a writable EditorState because there's no way to invalidate it if the EditorState changes (because it's not supposed to).

@etrepum
Copy link
Collaborator

etrepum commented Jan 7, 2025

I think the root cause is probably setRootElement(null) which probably just shouldn't be doing this

        // If content editable is unmounted we'll reset editor state back to original
        // (or pending) editor state since there will be no reconciliation
        this._editorState = pendingEditorState;
        this._pendingEditorState = null;
        this._window = null;

@ivailop7
Copy link
Collaborator

ivailop7 commented Jan 7, 2025

With Bob on this one, this doesn't seem like the right approach to solve this problem.

@etrepum
Copy link
Collaborator

etrepum commented Jan 7, 2025

#7023 is a cleaner approach, but I can't be entirely sure this is exactly how they are getting the editor to have a writable _editorState

@potatowagon
Copy link
Contributor Author

#7023 is a cleaner approach, but I can't be entirely sure this is exactly how they are getting the editor to have a writable _editorState

replied on discord to answer the how, closing this PR since its not the right approach

@potatowagon potatowagon closed this Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants