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

feat(richtext-lexical)!: lazy import React components to prevent client-only code from leaking into the server #4290

Merged
merged 16 commits into from
Dec 6, 2023

Conversation

AlessioGr
Copy link
Member

@AlessioGr AlessioGr commented Nov 28, 2023

Description

Fixes #4085

Breaking Change:

  1. Most important: If you are updating @payloadcms/richtext-lexical to v0.4.0 or higher, you will HAVE to update payload to the latest version as well. If you don't update it, payload likely won't start up due to validation errors. It's generally good practice to upgrade packages prefixed with @payloadcms/ together with payload and keep the versions in sync.

@payloadcms/richtext-slate is not affected by this.

  1. Every single property in the Feature interface which accepts a React component now no longer accepts a React component, but a function which imports a React component instead. This is done to ensure no unnecessary client-only code is leaked to the server when importing Features on a server.

Here's an example migration:

Old:

import { BlockIcon } from '../../lexical/ui/icons/Block'
...
Icon: BlockIcon,

New:

// import { BlockIcon } from '../../lexical/ui/icons/Block' // <= Remove this import
...
Icon: () =>
  // @ts-expect-error
  import('../../lexical/ui/icons/Block').then((module) => module.BlockIcon),

Or alternatively, if you're using default exports instead of named exports:

// import BlockIcon from '../../lexical/ui/icons/Block' // <= Remove this import
...
Icon: () =>
  // @ts-expect-error
  import('../../lexical/ui/icons/Block'),
  1. The types for SanitizedEditorConfig and EditorConfig have changed. Their respective lexical property no longer expects the LexicalEditorConfig. It now expects a function returning the LexicalEditorConfig. You will have to adjust this if you adjusted that property anywhere, e.g. when initializing the lexical field editor property, or when initializing a new headless editor.

  2. The following exports are now exported from the @payloadcms/richtext-lexical/components subpath exports instead of @payloadcms/richtext-lexical:

  • ToolbarButton
  • ToolbarDropdown
  • RichTextCell
  • RichTextField
  • defaultEditorLexicalConfig

You will have to adjust your imports, only if you import any of those properties in your project.

  • I have read and understand the CONTRIBUTING.md document in this repository.

Type of change

  • Chore (non-breaking change which does not add functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Change to the templates directory (does not affect core functionality)
  • Change to the examples directory (does not affect core functionality)
  • This change requires a documentation update

Checklist:

  • I have added tests that prove my fix is effective or that my feature works
  • Existing test suite passes locally with my changes
  • I have made corresponding changes to the documentation

@AlessioGr AlessioGr added the plugin: richtext-lexical @payloadcms/richtext-lexical label Nov 28, 2023
@AlessioGr
Copy link
Member Author

AlessioGr commented Nov 28, 2023

TODO:

  • Subpath exports. Export Clientside stuff by default and put utilities in utilities.ts, or export serverside stuff-only by default and put clientside stuff in components.ts?
  • Check once again if all utilities can now be imported on the server without weird errors
  • Check if subpath exports (package.json, using it internally in tests, using it internally in payload, using it externally) actually works

@AlessioGr AlessioGr changed the title chore(richtext-lexical): lazy import React components to prevent client-only code from leaking into the server feat(richtext-lexical): lazy import React components to prevent client-only code from leaking into the server Dec 1, 2023
@AlessioGr AlessioGr changed the title feat(richtext-lexical): lazy import React components to prevent client-only code from leaking into the server feat(richtext-lexical)!: lazy import React components to prevent client-only code from leaking into the server Dec 1, 2023
@AlessioGr AlessioGr merged commit 5de347f into main Dec 6, 2023
29 checks passed
@AlessioGr AlessioGr deleted the chore/lexical-lazy-imports branch December 6, 2023 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: richtext-lexical @payloadcms/richtext-lexical
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lexical plugin imports CSS
1 participant