Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/rich-text/src/create-element.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
/**
* Parse the given HTML into a body element.
*
* Note: The current implementation will return a shared reference, reset on
* each call to `createElement`. Therefore, you should not hold a reference to
* the value to operate upon asynchronously, as it may have unexpected results.
*
* @param {HTMLDocument} document The HTML document to use to parse.
* @param {string} html The HTML to parse.
*
* @return {HTMLBodyElement} Body element with parsed HTML.
*/
export function createElement( { implementation }, html ) {
const { body } = implementation.createHTMLDocument( '' );
body.innerHTML = html;
return body;
if ( ! createElement.body ) {
createElement.body = implementation.createHTMLDocument( '' ).body;
}

createElement.body.innerHTML = html;

return createElement.body;
}
7 changes: 6 additions & 1 deletion packages/rich-text/src/test/to-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import { JSDOM } from 'jsdom';
*/

import { toDom, applyValue } from '../to-dom';
import { createElement } from '../create-element';
import { spec } from './helpers';

const { window } = new JSDOM();
const { document } = window;

function createElement( { implementation }, html ) {
const { body } = implementation.createHTMLDocument( '' );
body.innerHTML = html;
return body;
}

describe( 'recordToDom', () => {
beforeAll( () => {
// Initialize the rich-text store.
Expand Down