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] Feature: Add version identifier to LexicalEditor constructor #6488

Merged
merged 9 commits into from
Aug 6, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented Aug 3, 2024

Description

New LexicalEditor.version static to help users diagnose installation issues.

Also refactors other __lexicalEditor code to avoid conflicts with multiple lexical builds on the page (RE #6481)

Inspecting the lexical editor's version can be done as follows (example assumes exactly one editor on the page):

> document.querySelector('[contenteditable]').__lexicalEditor.constructor.version
'0.17.0+dev.esm'

It does not have support for coming up with special build identifiers for the versions of lexical we build in CI and for the website that do not correspond to npm versions.

Closes #6145
Closes #5996

Test plan

There's an integration test that checks to make sure the version is set and accessible from the editor instance

Before

> oldLexical.createEditor().constructor.version
undefined
> lexical.createEditor().constructor.version
'0.17.0+dev.esm'

After

Using https://lexical-playground-git-fork-etrepum-version-a6c103-fbopensource.vercel.app/esm/

Screenshot 2024-08-03 at 4 08 56 PM

Copy link

vercel bot commented Aug 3, 2024

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 Aug 5, 2024 7:30pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 5, 2024 7: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 Aug 3, 2024
Copy link

github-actions bot commented Aug 3, 2024

size-limit report 📦

Path Size
lexical - cjs 29.02 KB (0%)
lexical - esm 28.85 KB (0%)
@lexical/rich-text - cjs 37.37 KB (0%)
@lexical/rich-text - esm 28.34 KB (0%)
@lexical/plain-text - cjs 36.03 KB (0%)
@lexical/plain-text - esm 25.6 KB (0%)
@lexical/react - cjs 39.27 KB (0%)
@lexical/react - esm 29.75 KB (0%)

@etrepum
Copy link
Collaborator Author

etrepum commented Aug 4, 2024

I think these are flaky collab test failures

@@ -84,7 +84,7 @@ handle external UI state and UI features relating to specific types of node.
If any existing nodes are in the DOM, and skipInitialization is not true, the listener
will be called immediately with an updateTag of 'registerMutationListener' where all
nodes have the 'created' NodeMutation. This can be controlled with the skipInitialization option
(default is currently true for backwards compatibility in 0.16.x but will change to false in 0.17.0).
(default is currently true for backwards compatibility in 0.17.x but will change to false in 0.18.0).
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the deprecation policy here since 0.17.0 was the first release with the changes to registerMutationListener (#6357)

@@ -52,6 +52,10 @@ export default defineConfig(({command}) => {
from: /__DEV__/g,
to: 'true',
},
{
from: 'process.env.LEXICAL_VERSION',
to: JSON.stringify(`${process.env.npm_package_version}+git`),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The playground is never built with an npm release of lexical since it directly includes all of the source

Copy link
Contributor

@potatowagon potatowagon left a comment

Choose a reason for hiding this comment

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

👍

@etrepum etrepum added this pull request to the merge queue Aug 6, 2024
Merged via the queue into facebook:main with commit 20e4ea1 Aug 6, 2024
41 checks passed
@etrepum etrepum deleted the version-identifier branch August 6, 2024 18:20
return activeEditor;
}

function collectBuildInformation(): string {
Copy link
Member

Choose a reason for hiding this comment

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

@etrepum nitpicking but such detailed error is something I'd consider gating under the __DEV__ build or developer extension. I don't think it's very common to have multiple editors on the same page and it's less common to make this mistake, and there is quite some logic in here 679 bytes minimized.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Given the amount of bug reports for this one issue I was motivated to include it, I think a lot of people end up with the prod build for various reasons. You could put it behind a flag so it doesn't get included in www? Once dev tools gets a release with this functionality we could stub the implementation out with a string that says to install the dev tools to diagnose. We are still talking about <1kb before compression.

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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Add version/build identifier to LexicalEditor
4 participants