fix(richtext-lexical): remove Lazy field & cell components, which fixes RSC errors, likely due to RSC bug where React.lazy's are not handled properly
This commit is contained in:
@@ -77,20 +77,7 @@ export type RichTextAdapter<
|
||||
Value extends object = object,
|
||||
AdapterProps = any,
|
||||
ExtraFieldProperties = {},
|
||||
> = RichTextAdapterBase<Value, AdapterProps, ExtraFieldProperties> &
|
||||
(
|
||||
| {
|
||||
CellComponent: React.FC<
|
||||
CellComponentProps<RichTextField<Value, AdapterProps, ExtraFieldProperties>>
|
||||
>
|
||||
FieldComponent: React.FC<RichTextFieldProps<Value, AdapterProps, ExtraFieldProperties>>
|
||||
}
|
||||
| {
|
||||
LazyCellComponent: () => Promise<
|
||||
React.FC<CellComponentProps<RichTextField<Value, AdapterProps, ExtraFieldProperties>>>
|
||||
>
|
||||
LazyFieldComponent: () => Promise<
|
||||
React.FC<RichTextFieldProps<Value, AdapterProps, ExtraFieldProperties>>
|
||||
>
|
||||
}
|
||||
)
|
||||
> = RichTextAdapterBase<Value, AdapterProps, ExtraFieldProperties> & {
|
||||
CellComponent: React.FC<any>
|
||||
FieldComponent: React.FC<RichTextFieldProps<Value, AdapterProps, ExtraFieldProperties>>
|
||||
}
|
||||
|
||||
@@ -94,8 +94,6 @@ export default joi.object({
|
||||
.keys({
|
||||
CellComponent: componentSchema.optional(),
|
||||
FieldComponent: componentSchema.optional(),
|
||||
LazyCellComponent: joi.func().optional(),
|
||||
LazyFieldComponent: joi.func().optional(),
|
||||
afterReadPromise: joi.func().optional(),
|
||||
outputSchema: joi.func().optional(),
|
||||
populationPromise: joi.func().optional(),
|
||||
|
||||
@@ -444,8 +444,6 @@ export const richText = baseField.keys({
|
||||
.keys({
|
||||
CellComponent: componentSchema.optional(),
|
||||
FieldComponent: componentSchema.optional(),
|
||||
LazyCellComponent: joi.func().optional(),
|
||||
LazyFieldComponent: joi.func().optional(),
|
||||
afterReadPromise: joi.func().optional(),
|
||||
outputSchema: joi.func().optional(),
|
||||
populationPromise: joi.func().optional(),
|
||||
|
||||
@@ -3,12 +3,15 @@ import type { SerializedEditorState } from 'lexical'
|
||||
import type { EditorConfig as LexicalEditorConfig } from 'lexical/LexicalEditor.js'
|
||||
import type { RichTextAdapter } from 'payload/types'
|
||||
|
||||
import { withMergedProps } from '@payloadcms/ui'
|
||||
import { withNullableJSONSchemaType } from 'payload/utilities'
|
||||
|
||||
import type { FeatureProviderServer, ResolvedServerFeatureMap } from './field/features/types.js'
|
||||
import type { SanitizedServerEditorConfig } from './field/lexical/config/types.js'
|
||||
import type { AdapterProps } from './types.js'
|
||||
|
||||
import { RichTextCell } from './cell/index.js'
|
||||
import { RichTextField } from './field/index.js'
|
||||
import {
|
||||
defaultEditorConfig,
|
||||
defaultEditorFeatures,
|
||||
@@ -71,28 +74,14 @@ export function lexicalEditor(props?: LexicalEditorProps): LexicalRichTextAdapte
|
||||
}
|
||||
|
||||
return {
|
||||
LazyCellComponent: () =>
|
||||
// @ts-expect-error
|
||||
import('./cell/index.js').then((module) => {
|
||||
const RichTextCell = module.RichTextCell
|
||||
return import('@payloadcms/ui').then((module2) =>
|
||||
module2.withMergedProps({
|
||||
Component: RichTextCell,
|
||||
toMergeIntoProps: { lexicalEditorConfig: finalSanitizedEditorConfig.lexical }, // lexicalEditorConfig is serializable
|
||||
}),
|
||||
)
|
||||
}),
|
||||
|
||||
LazyFieldComponent: () =>
|
||||
import('./field/index.js').then((module) => {
|
||||
const RichTextField = module.RichTextField
|
||||
return import('@payloadcms/ui').then((module2) =>
|
||||
module2.withMergedProps({
|
||||
Component: RichTextField,
|
||||
toMergeIntoProps: { lexicalEditorConfig: finalSanitizedEditorConfig.lexical }, // lexicalEditorConfig is serializable
|
||||
}),
|
||||
)
|
||||
}),
|
||||
CellComponent: withMergedProps({
|
||||
Component: RichTextCell,
|
||||
toMergeIntoProps: { lexicalEditorConfig: finalSanitizedEditorConfig.lexical },
|
||||
}),
|
||||
FieldComponent: withMergedProps({
|
||||
Component: RichTextField,
|
||||
toMergeIntoProps: { lexicalEditorConfig: finalSanitizedEditorConfig.lexical },
|
||||
}),
|
||||
afterReadPromise: ({ field, incomingEditorState, siblingDoc }) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const promises: Promise<void>[] = []
|
||||
|
||||
@@ -264,35 +264,8 @@ export const mapFields = (args: {
|
||||
* Handle RichText Field Components, Cell Components, and component maps
|
||||
*/
|
||||
if (field.type === 'richText' && 'editor' in field) {
|
||||
let RichTextFieldComponent
|
||||
let RichTextCellComponent
|
||||
|
||||
const isLazyField = 'LazyFieldComponent' in field.editor
|
||||
const isLazyCell = 'LazyCellComponent' in field.editor
|
||||
|
||||
if (isLazyField) {
|
||||
RichTextFieldComponent = React.lazy(() => {
|
||||
return 'LazyFieldComponent' in field.editor
|
||||
? field.editor.LazyFieldComponent().then((resolvedComponent) => ({
|
||||
default: resolvedComponent,
|
||||
}))
|
||||
: null
|
||||
})
|
||||
} else if ('FieldComponent' in field.editor) {
|
||||
RichTextFieldComponent = field.editor.FieldComponent
|
||||
}
|
||||
|
||||
if (isLazyCell) {
|
||||
RichTextCellComponent = React.lazy(() => {
|
||||
return 'LazyCellComponent' in field.editor
|
||||
? field.editor.LazyCellComponent().then((resolvedComponent) => ({
|
||||
default: resolvedComponent,
|
||||
}))
|
||||
: null
|
||||
})
|
||||
} else if ('CellComponent' in field.editor) {
|
||||
RichTextCellComponent = field.editor.CellComponent
|
||||
}
|
||||
const RichTextFieldComponent = field.editor.FieldComponent
|
||||
const RichTextCellComponent = field.editor.CellComponent
|
||||
|
||||
if (typeof field.editor.generateComponentMap === 'function') {
|
||||
const result = field.editor.generateComponentMap({ config, schemaPath: path })
|
||||
|
||||
Reference in New Issue
Block a user