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

upgrade all the prosemirror libs to latest (incl. regenerating yarn.lock) #350

Merged
merged 6 commits into from
Feb 21, 2024

Conversation

twrichards
Copy link
Contributor

@twrichards twrichards commented Feb 20, 2024

When attempting to upgrade prosemirror-view from 1.29.1 to 1.33.1 (to take advantage of ProseMirror/prosemirror-view#165 and ProseMirror/prosemirror-view#166, as a pre-requisite to #349) I ran into some breaking changes to the types, notably to reflect type signature changes of getPos function (introduced in prosemirror-view 1.30.2 - ProseMirror/prosemirror-view#153 - note the warning ProseMirror/prosemirror-view#153 (comment)) but also cascaded into requiring upgrade of prosemirror-state... so for good measure decided to upgrade all the prosemirror libs to latest.

There were some very strange incompatibilities after I'd done this, which AFAICT derived from multiple conflicting versions of packages referenced in the yarn.lock so I decided to delete and regenerate, which solved all the strange issues - but has resulted in a chunky diff - sorry.

@twrichards twrichards changed the base branch from main to CI/improve-GHA-triggers February 21, 2024 09:36
Base automatically changed from CI/improve-GHA-triggers to main February 21, 2024 10:04
Copy link
Member

@davidfurey davidfurey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, but lgtm.

@@ -171,7 +171,7 @@ const createNodeView = <
): NodeViewCreator => (initElementNode, view, _getPos, _, innerDecos) => {
const dom = document.createElement("div");
dom.contentEditable = "false";
const getPos = typeof _getPos === "boolean" ? () => 0 : _getPos;
const getPos = () => _getPos() ?? NaN;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required?

Copy link
Contributor Author

@twrichards twrichards Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from PR description

notably to reflect type signature changes of getPos function (introduced in prosemirror-view 1.30.2 - ProseMirror/prosemirror-view#153 - note the warning ProseMirror/prosemirror-view#153 (comment))

... the type signature of the getPos function passed in on line 171 (called _getPos) is now () => number | undefined which needs to be handled at some point as the getPos everywhere else in @guardian/prosemirror-elements expects () => number and the ripple effect of changing those type signatures then wasn't handled by the prosemirror libs that the functions are sometimes passed back into. So I changed this to return NaN if _getPos returns undefined so that it will explode in the relevant places whilst still adhering to the type number.

You're right to raise this though, as whatever was happening before would possibly return 0, which I didn't think was correct as the undefined is only returned if the node is not in the doc and returning 0 would imply its at the start of the doc... but perhaps there is logic littered around which relies on it falling back to zero rather than exploding. On balance, I think this change is worth it and nothing has exploded in my anecdotal testing thus far, let me know if you disagree though and I can perhaps have another go at propagating the () => number | undefined out further through the codebase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing that, too early in the morning.

@twrichards twrichards merged commit 73e41d8 into main Feb 21, 2024
3 checks passed
@twrichards twrichards deleted the upgrade/prosemirror-view branch February 21, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants