Skip to content

Commit

Permalink
fix(core): 🐛 fix DOMParser error on SSR
Browse files Browse the repository at this point in the history
Closes #512
  • Loading branch information
thierrymichel authored and xavierfoucrier committed Jan 8, 2023
1 parent adf46eb commit cadba05
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/core/src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { schemaAttribute } from '../schemas/attribute';

export class Dom {
private _attr: ISchemaAttribute = schemaAttribute;
private _parser: DOMParser = new DOMParser();
private _parser: DOMParser;

/**
* Convert HTMLDocument to string.
Expand All @@ -36,6 +36,10 @@ export class Dom {
// see https://github.com/barbajs/barba/issues/362
// Seems that using DOMParser.parseFromString causes this issue.
public toDocument(htmlString: string): HTMLDocument {
/* istanbul ignore else */
if (!this._parser) {
this._parser = new DOMParser();
}
return this._parser.parseFromString(htmlString, 'text/html');
}

Expand Down

0 comments on commit cadba05

Please sign in to comment.