diff --git a/formats/table/index.js b/formats/table/index.js index 1c72018885..eb23272cbe 100644 --- a/formats/table/index.js +++ b/formats/table/index.js @@ -350,16 +350,22 @@ class RowContainer extends Container { this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer) ) { - const { domNode } = this.children.head.children.head.children.head; + const domNode = this.children.head.children.head.children?.head?.domNode || null; const formats = {}; - Object.keys(TABLE_FORMATS).forEach((format) => { - const value = domNode.dataset[format.toLowerCase()]; - if (value) { - formats[format] = value; - } - }); + + if (domNode) { + Object.keys(TABLE_FORMATS).forEach((format) => { + const value = domNode.dataset[format.toLowerCase()]; + + if (value) { + formats[format] = value; + } + }); + } + this.wrap(this.statics.requiredContainer.blotName, formats); } + super.optimize(...args); } } @@ -530,7 +536,7 @@ class TableContainer extends Container { const formats = {}; const childElem = this.cells()[0].domNode.firstElementChild; Object.keys(TABLE_FORMATS).forEach((format) => { - const value = childElem.dataset[format.toLowerCase()]; + const value = childElem?.dataset[format.toLowerCase()]; if (value) { formats[format] = value; } diff --git a/test/functional/epic.js b/test/functional/epic.js index e94dae1074..ecf28f0506 100644 --- a/test/functional/epic.js +++ b/test/functional/epic.js @@ -490,6 +490,34 @@ if (!isMac) { }); } +describe('Mutation content with table', function () { + it('Should be no errors when table is inserted to editor (T1180959)', async function () { + const browser = await puppeteer.launch({ + headless: false, + }); + const page = await browser.newPage(); + + await page.goto(`${HOST}/table_drag_drop.html`); + await page.waitForSelector('.ql-editor', { timeout: 10000 }); + + page.on('pageerror', () => { + expect(true).toEqual(false); + }); + + await page.evaluate(() => { + const editor = document.querySelector('.ql-editor'); + + const table = document.createElement('table'); + + table.innerHTML = '
Custom text
Init text
+