Skip to content

Commit

Permalink
fix(core): 🐛 fix container replacement in the dom
Browse files Browse the repository at this point in the history
This fix #479.
  • Loading branch information
xavierfoucrier committed May 1, 2023
1 parent edcd7d7 commit aec3143
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { schemaAttribute } from '../schemas/attribute';
export class Dom {
private _attr: ISchemaAttribute = schemaAttribute;
private _parser: DOMParser;
private _sibling: Element | null;

/**
* Convert HTMLDocument to string.
Expand Down Expand Up @@ -93,6 +94,7 @@ export class Dom {
*/
public removeContainer(container: HTMLElement) {
if (document.body.contains(container)) {
this._sibling = container.previousElementSibling;
container.parentNode.removeChild(container);
}
}
Expand All @@ -101,10 +103,10 @@ export class Dom {
* Add container before next sibling or at the end of the wrapper.
*/
public addContainer(container: HTMLElement, wrapper: HTMLElement) {
const existingContainer = this.getContainer();
const existingSibling = this.getContainer() || this._sibling;

if (existingContainer) {
this._insertAfter(container, existingContainer);
if (existingSibling) {
this._insertAfter(container, existingSibling);
} else {
wrapper.appendChild(container);
}
Expand Down

0 comments on commit aec3143

Please sign in to comment.