-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix recently introduce bug affecting elements #406
Conversation
@@ -197,7 +197,8 @@ export abstract class ProseMirrorFieldView extends FieldView<string> { | |||
const diffStart = node.content.findDiffStart(state.doc.content); | |||
const diffEnd = node.content.findDiffEnd(state.doc.content); | |||
|
|||
if (diffStart && diffEnd) { | |||
// Check for null specifically, rather than falsiness, because a diff starting at pos 0 is a valid diff | |||
if (diffStart !== null && diffEnd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot! Might be nice to also check diffEnd is not null
? Who knows, maybe at some point negative positions will be valid, and diffEnd
could be zero but still greater than diffStart
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, !== null
does seem like what we really want to check for there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally and all the desired behaviour seemed to be working 🥳
Background
Developers and users have noticed some unusual behaviour in elements (in Composer) recently:
Through testing we identified that version
9.6.1
(the most recent release of prosemirror-elements) introduced the change. The biggest and most relevant change in this release was https://github.com/guardian/prosemirror-elements/pulls?q=is%3Apr+sort%3Aupdated-desc+is%3AclosedThat change was reverted in Composer and the issues seem to be resolved there now: https://github.com/guardian/flexible-content/pull/4803
What does this PR change
This PR is intended to solve the bugs reported above.
The bug was caused by a subtle change in our logic during the refactor in the selection PR.
Previously, we would check for a 'diff' between the previous state of the node represented by a text view, and its updated state, as follows:
I had changed this check to:
However, a diff could often start at position 0 relative to the
innerEditorView
represented by the text field, e.g. if the entire text field had changed, as part of wider changes to an entire element, or with a change only affecting the initial character.Changing this check to
if (diffStart !== null && diffEnd)
seems to have resolved the issues mentioned above when testing locally.Tests
I've updated the existing tests to add some more clarity about when a node is passed in versus when a new selection is passed in.
I've also added some new tests that look at the internal state of the inner editor, to cover the case that occurred in a bug. Without this PR's fix, the following test fails.
should update its internal doc when a node with different content is passed in, with different content starting at the first position of the inner editor
Let me know if what's happening in these tests is unclear, I'm happy to pair.
How to test
yarn yalc
and use in flexible-content locally withyalc add @guardian/prosemirror-elements
thennpm i
in the composer directory.