-
-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3506 from udecode/fix/perf
Plate 38: Performance optimization
- Loading branch information
Showing
24 changed files
with
519 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
'@udecode/plate-core': major | ||
--- | ||
|
||
- Change `plugin.options` merging behavior from deep merge to shallow merge. | ||
- This affects `.extend()`, `.configure()`, and other methods that modify plugin options. | ||
- This update addresses a **performance regression** introduced in v37 that affected editor creation. | ||
|
||
Before: | ||
|
||
```ts | ||
const plugin = createSlatePlugin({ | ||
key: 'test', | ||
options: { nested: { a: 1 } }, | ||
}).extend({ | ||
options: { nested: { b: 1 } }, | ||
}); | ||
|
||
// Result: { nested: { a: 1, b: 1 } } | ||
``` | ||
|
||
After: | ||
|
||
```ts | ||
const plugin = createSlatePlugin({ | ||
key: 'test', | ||
options: { nested: { a: 1 } }, | ||
}).extend(({ getOptions }) => ({ | ||
options: { | ||
...getOptions(), | ||
nested: { ...getOptions().nested, b: 1 }, | ||
}, | ||
})); | ||
|
||
// Result: { nested: { a: 1, b: 1 } } | ||
``` | ||
|
||
Migration: | ||
|
||
- If you're using nested options and want to preserve the previous behavior, you need to manually spread both the top-level options and the nested objects. | ||
- If you're not using nested options, no changes are required. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import mergeWith from 'lodash/mergeWith.js'; | ||
|
||
import type { SlatePlugin } from '../lib'; | ||
|
||
export function mergePlugins<T>(basePlugin: T, ...sourcePlugins: any[]): T { | ||
return mergeWith( | ||
{}, | ||
basePlugin, | ||
...sourcePlugins, | ||
(objValue: unknown, srcValue: unknown, key: keyof SlatePlugin) => { | ||
// Overwrite array (including plugins) without cloning | ||
if (Array.isArray(srcValue)) { | ||
return srcValue; | ||
} | ||
// Shallow merge options | ||
if (key === 'options') { | ||
return { ...(objValue as any), ...(srcValue as any) }; | ||
} | ||
} | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.