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-react] Breaking change: Deprecate public default exports #6088

Merged
merged 5 commits into from
May 16, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented May 11, 2024

Description

There are a handful of reasons to avoid default exports described briefly in #6079. A compelling reason not to use them is in our case is that they are rarely and inconsistently used in monorepo entrypoints, but there are other more technical reasons that they are not ideal (they generate confusing API docs for example)

  • Adds named exports for all public entrypoints (only the @lexical/react package had modules with default exports)
  • Marks default exports with @deprecated comments
  • Updates monorepo code and docs to use named exports
  • Adds lint rule to prevent future inconsistencies
  • Uses the automatic jsx runtime so we don't have errors if an import * as React from 'react' is forgotten. I wonder why this isn't the default preset yet, given that it's been available for a few years.
  • Switches rollup to named exports
  • Removes a console.log from a unit test
  • Fixes scripts/update-flowconfig to inject the @flow strict into the boilerplate template header correctly

This is isolated to the @lexical/rect package and affects the following modules:

  • @lexical/react/LexicalClickableLinkPlugin (now exports name ClickableLinkPlugin)
  • @lexical/react/LexicalErrorBoundary (now exports name LexicalErrorBoundary)
  • @lexical/react/LexicalTableOfContents -> @lexical/react/LexicalTableOfContentsPlugin(which exports name TableOfContentsPlugin) - the old module still exists with only a default export
  • @lexical/react/useLexicalEditable (now exports name useLexicalEditable)
  • @lexical/react/useLexicalSubscription (now exports name useLexicalSubscription)

Closes: #6079

Test plan

  • All test suites should still pass
  • Reviewer(s) should manually verify that default exports are still available in all of the entrypoints that were changed
  • Someone with knowledge of www should verify that this will not cause problems, I believe I updated the flow types correctly although one case seemed wrong to begin with (will note in review comment) but the change to rollup's outputOptions export: 'named' could be problematic depending on what haste (or whatever that's called these days) does with exports named default. I don't think it's possible to make rollup output something like module.exports = function defaultExport() {}; module.exports.defaultExport = module.exports; which is pretty much the only thing that would have the same cjs semantics. It could also of course be fixed with a codemod fairly easily as there are only five renames here.

@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 May 11, 2024
Copy link

vercel bot commented May 11, 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 May 11, 2024 5:11pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 11, 2024 5:11pm

@@ -7,6 +7,8 @@
* @flow strict
*/

declare export function MLCClickableLinkPlugin({
declare export function ClickableLinkPlugin({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seemed wrong, since no such name was present. Not sure what was going on here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep it as is and mark deprecated

Copy link
Contributor

@StyleT StyleT left a comment

Choose a reason for hiding this comment

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

This change (and the lint rule) really really good in a sense that it allows to unify approach to exports.

However breaking changes here seems to be unnecessary... This will be especially painful for larger codebases.

Better approach would be to do both named + default export while marking default as deprecated, announce change, let people migrate at their pace, deprecate defaults.

But let's hear other opinions too!

P.S.: Merge to Meta's WWW may be painful with this

@etrepum
Copy link
Collaborator Author

etrepum commented May 13, 2024

This PR does that, default exports are still there, but it's breaking in the sense that working with the newer docs/examples won't be compatible with older lexical

@etrepum
Copy link
Collaborator Author

etrepum commented May 13, 2024

Also technically in cjs this is a breaking change if the bundler doesn't do the right thing with exports named default with these rollup settings

Copy link
Contributor

@StyleT StyleT left a comment

Choose a reason for hiding this comment

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

LGTM with 1 comment!

@@ -7,6 +7,8 @@
* @flow strict
*/

declare export function MLCClickableLinkPlugin({
declare export function ClickableLinkPlugin({
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep it as is and mark deprecated

@StyleT
Copy link
Contributor

StyleT commented May 13, 2024

This PR does that, default exports are still there, but it's breaking in the sense that working with the newer docs/examples won't be compatible with older lexical

yep, I see now, by bad. Still asleep here :P

@etrepum
Copy link
Collaborator Author

etrepum commented May 13, 2024

@StyleT we could keep that flow type as-is, but it references a symbol that didn't exist in the first place? Would probably be better to remove it if using a name that exists isn't the proper fix

@StyleT
Copy link
Contributor

StyleT commented May 13, 2024

@StyleT we could keep that flow type as-is, but it references a symbol that didn't exist in the first place? Would probably be better to remove it if using a name that exists isn't the proper fix

yep, you're right. It's just a flow file. Good to be merged. Let's allow others at least a day to look at it

@StyleT StyleT added the extended-tests Run extended e2e tests on a PR label May 16, 2024
@StyleT StyleT added this pull request to the merge queue May 16, 2024
Merged via the queue into facebook:main with commit 956ae8b May 16, 2024
82 checks passed
@etrepum etrepum deleted the only-named-public-exports branch May 17, 2024 17:00
etrepum added a commit to etrepum/lexical that referenced this pull request May 17, 2024
StyleT added a commit that referenced this pull request May 17, 2024
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.

3 participants