perf(richtext-lexical): do not send default lexical editor config to client (#9318)

We can just get the default config from the client, if the server passes
undefined. This wasted bandwidth and unnecessarily increased the html
size
This commit is contained in:
Alessio Gravili
2024-11-18 17:28:55 -07:00
committed by GitHub
parent fade739f77
commit f7fc8a2ea0
4 changed files with 7 additions and 5 deletions

View File

@@ -23,7 +23,7 @@ export const RichTextField: React.FC<LexicalRichTextFieldProps> = (props) => {
clientFeatures,
featureClientSchemaMap,
field,
lexicalEditorConfig,
lexicalEditorConfig = defaultEditorLexicalConfig,
schemaPath,
} = props

View File

@@ -83,6 +83,8 @@ export function lexicalEditor(props?: LexicalEditorProps): LexicalRichTextAdapte
finalSanitizedEditorConfig = deepCopyObject(defaultSanitizedServerEditorConfig)
delete finalSanitizedEditorConfig.lexical // We don't want to send the default lexical editor config to the client
resolvedFeatureMap = finalSanitizedEditorConfig.resolvedFeatureMap
} else {
const rootEditor = config.editor
@@ -116,7 +118,7 @@ export function lexicalEditor(props?: LexicalEditorProps): LexicalRichTextAdapte
finalSanitizedEditorConfig = {
features: sanitizeServerFeatures(resolvedFeatureMap),
lexical,
lexical: props.lexical,
resolvedFeatureMap,
}
}

View File

@@ -14,12 +14,12 @@ import type { LexicalFieldAdminProps } from '../../types.js'
export type ServerEditorConfig = {
features: FeatureProviderServer<any, any, any>[]
lexical?: LexicalEditorConfig
lexical?: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.
}
export type SanitizedServerEditorConfig = {
features: SanitizedServerFeatures
lexical: LexicalEditorConfig
lexical: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.
resolvedFeatureMap: ResolvedServerFeatureMap
}

View File

@@ -97,7 +97,7 @@ export type LexicalRichTextFieldProps = {
}
featureClientSchemaMap: FeatureClientSchemaMap
initialLexicalFormState: InitialLexicalFormState
lexicalEditorConfig: LexicalEditorConfig
lexicalEditorConfig: LexicalEditorConfig | undefined // Undefined if default lexical editor config should be used
} & Pick<ServerFieldBase, 'permissions'> &
RichTextFieldClientProps<SerializedEditorState, AdapterProps, object>