diff --git a/.changeset/clean-bugs-rush.md b/.changeset/clean-bugs-rush.md new file mode 100644 index 000000000..a6a10a152 --- /dev/null +++ b/.changeset/clean-bugs-rush.md @@ -0,0 +1,5 @@ +--- +"@tiptap/core": patch +--- + +There was a bug where doing a `.configure` on an extension, node or mark would overwrite the extensions options instead of being merged with the default options. diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index e6e790bbf..97200301f 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -459,8 +459,8 @@ export class Extension { // with different calls of `configure` const extension = this.extend({ ...this.config, - addOptions() { - return mergeDeep(this.parent?.() || {}, options) as Options + addOptions: () => { + return mergeDeep(this.options as Record, options) as Options }, }) diff --git a/packages/core/src/Mark.ts b/packages/core/src/Mark.ts index 9ff572b0f..f365ce40e 100644 --- a/packages/core/src/Mark.ts +++ b/packages/core/src/Mark.ts @@ -591,8 +591,8 @@ export class Mark { // with different calls of `configure` const extension = this.extend({ ...this.config, - addOptions() { - return mergeDeep(this.parent?.() || {}, options) as Options + addOptions: () => { + return mergeDeep(this.options as Record, options) as Options }, }) diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index c1fd865f7..a79d3a9aa 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -782,8 +782,8 @@ export class Node { // with different calls of `configure` const extension = this.extend({ ...this.config, - addOptions() { - return mergeDeep(this.parent?.() || {}, options) as Options + addOptions: () => { + return mergeDeep(this.options as Record, options) as Options }, }) diff --git a/tests/cypress/integration/core/extendExtensions.spec.ts b/tests/cypress/integration/core/extendExtensions.spec.ts index f57838a19..b6618cc4f 100644 --- a/tests/cypress/integration/core/extendExtensions.spec.ts +++ b/tests/cypress/integration/core/extendExtensions.spec.ts @@ -393,26 +393,47 @@ describe('extend extensions', () => { }) }) + it('should configure to be in addition to the parent options', () => { + const parentExtension = Extendable + .create({ + name: 'parentExtension', + addOptions() { + return { parent: 'exists', overwrite: 'parent' } + }, + }) + + const childExtension = parentExtension + .configure({ child: 'exists-too', overwrite: 'child' }) + + expect(childExtension.options).to.deep.eq({ + parent: 'exists', + child: 'exists-too', + overwrite: 'child', + }) + }) + it('should deeply merge options when extending a configured extension', () => { const parentExtension = Extendable .create({ name: 'parentExtension', addOptions() { - return { defaultOptions: 'is-overwritten' } + return { defaultOptions: 'exists', overwrite: 'parent' } }, }) const childExtension = parentExtension - .configure({ configuredOptions: 'exists-too' }).extend({ + .configure({ configuredOptions: 'exists-too', overwrite: 'configure' }).extend({ name: 'childExtension', addOptions() { - return { ...this.parent?.(), additionalOptions: 'exist-too' } + return { ...this.parent?.(), additionalOptions: 'exist-too', overwrite: 'child' } }, }) expect(childExtension.options).to.deep.eq({ + defaultOptions: 'exists', configuredOptions: 'exists-too', additionalOptions: 'exist-too', + overwrite: 'child', }) }) })