Skip to content

Commit 07f4c03

Browse files
authoredJul 17, 2024··
fix(core): configuring extensions should add to the parent's options not replace them (#5357)
* fix(core): configuring extensions should add to the parent's options not replace them * fix: order of tests
1 parent a21a122 commit 07f4c03

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed
 

‎.changeset/clean-bugs-rush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tiptap/core": patch
3+
---
4+
5+
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.

‎packages/core/src/Extension.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ export class Extension<Options = any, Storage = any> {
459459
// with different calls of `configure`
460460
const extension = this.extend({
461461
...this.config,
462-
addOptions() {
463-
return mergeDeep(this.parent?.() || {}, options) as Options
462+
addOptions: () => {
463+
return mergeDeep(this.options as Record<string, any>, options) as Options
464464
},
465465
})
466466

‎packages/core/src/Mark.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ export class Mark<Options = any, Storage = any> {
591591
// with different calls of `configure`
592592
const extension = this.extend({
593593
...this.config,
594-
addOptions() {
595-
return mergeDeep(this.parent?.() || {}, options) as Options
594+
addOptions: () => {
595+
return mergeDeep(this.options as Record<string, any>, options) as Options
596596
},
597597
})
598598

‎packages/core/src/Node.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ export class Node<Options = any, Storage = any> {
782782
// with different calls of `configure`
783783
const extension = this.extend({
784784
...this.config,
785-
addOptions() {
786-
return mergeDeep(this.parent?.() || {}, options) as Options
785+
addOptions: () => {
786+
return mergeDeep(this.options as Record<string, any>, options) as Options
787787
},
788788
})
789789

‎tests/cypress/integration/core/extendExtensions.spec.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -393,26 +393,47 @@ describe('extend extensions', () => {
393393
})
394394
})
395395

396+
it('should configure to be in addition to the parent options', () => {
397+
const parentExtension = Extendable
398+
.create({
399+
name: 'parentExtension',
400+
addOptions() {
401+
return { parent: 'exists', overwrite: 'parent' }
402+
},
403+
})
404+
405+
const childExtension = parentExtension
406+
.configure({ child: 'exists-too', overwrite: 'child' })
407+
408+
expect(childExtension.options).to.deep.eq({
409+
parent: 'exists',
410+
child: 'exists-too',
411+
overwrite: 'child',
412+
})
413+
})
414+
396415
it('should deeply merge options when extending a configured extension', () => {
397416
const parentExtension = Extendable
398417
.create({
399418
name: 'parentExtension',
400419
addOptions() {
401-
return { defaultOptions: 'is-overwritten' }
420+
return { defaultOptions: 'exists', overwrite: 'parent' }
402421
},
403422
})
404423

405424
const childExtension = parentExtension
406-
.configure({ configuredOptions: 'exists-too' }).extend({
425+
.configure({ configuredOptions: 'exists-too', overwrite: 'configure' }).extend({
407426
name: 'childExtension',
408427
addOptions() {
409-
return { ...this.parent?.(), additionalOptions: 'exist-too' }
428+
return { ...this.parent?.(), additionalOptions: 'exist-too', overwrite: 'child' }
410429
},
411430
})
412431

413432
expect(childExtension.options).to.deep.eq({
433+
defaultOptions: 'exists',
414434
configuredOptions: 'exists-too',
415435
additionalOptions: 'exist-too',
436+
overwrite: 'child',
416437
})
417438
})
418439
})

0 commit comments

Comments
 (0)
Please sign in to comment.