-
Notifications
You must be signed in to change notification settings - Fork 937
Description
Description
Root cause:
withComponent is defined here:
plate/packages/core/src/react/plugin/toPlatePlugin.ts
Lines 93 to 98 in 309533a
| plugin.withComponent = (component) => { | |
| return plugin.extend({ | |
| node: { component }, | |
| render: { node: component }, | |
| }) as any; | |
| }; |
overrideEditor is defined here:
plate/packages/core/src/lib/plugin/createSlatePlugin.ts
Lines 240 to 253 in 309533a
| plugin.overrideEditor = (extension) => { | |
| const newPlugin = { ...plugin }; | |
| newPlugin.__apiExtensions = [ | |
| ...(newPlugin.__apiExtensions as any), | |
| { | |
| extension, | |
| isOverride: true, | |
| isPluginSpecific: false, | |
| isTransform: true, | |
| }, | |
| ]; | |
| return createSlatePlugin(newPlugin) as any; | |
| }; |
createPlatePlugin is defined here:
plate/packages/core/src/react/plugin/createPlatePlugin.ts
Lines 37 to 50 in 309533a
| export const createPlatePlugin = < | |
| K extends string = any, | |
| O = {}, | |
| A = {}, | |
| T = {}, | |
| >( | |
| config: | |
| | ((editor: PlateEditor) => PlatePluginConfig<K, O, A, T>) | |
| | PlatePluginConfig<K, O, A, T> = {} | |
| ): PlatePlugin<PluginConfig<K, O, A, T>> => { | |
| const plugin = createSlatePlugin(config as any); | |
| return toPlatePlugin(plugin as any) as any; | |
| }; |
Note that toPlatePlugin called from createPlatePlugin makes a copy of the plugin.
Since overrideEditor is an arrow function, the plugin is actually retrieved from the outer scope, which is the slate plugin that not yet returned from createSlatePlugin, not the one copied and created by createPlatePlugin. Therefore, the plugin returned after overrideEditor call will not contain withComponent
Reproduction URL
No response
Reproduction steps
console.log(createTPlatePlugin({ key: 'mykey' }).overrideEditor(() => ({})).withComponent === undefined)
// truePlate version
42
Slate React version
not related
Screenshots
No response
Logs
No response
Browsers
No response