Skip to content

Commit 68252cb

Browse files
authored
fix(xml-builder): move DOMParser init from module level to function call (#7426)
Remove DOMParser initialization import side-effect. Prevents the entire lib from breaking in environments where global DOMParser is not available and XML parsing is not required.
1 parent eb2bf70 commit 68252cb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/xml-builder/src/xml-parser.browser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const parser = new DOMParser();
1+
let parser: DOMParser | undefined;
22

33
/**
44
* Cases where this differs from fast-xml-parser:
@@ -9,6 +9,10 @@ const parser = new DOMParser();
99
* @internal
1010
*/
1111
export function parseXML(xmlString: string): any {
12+
if (!parser) {
13+
parser = new DOMParser();
14+
}
15+
1216
const xmlDocument = parser.parseFromString(xmlString, "application/xml");
1317

1418
if (xmlDocument.getElementsByTagName("parsererror").length > 0) {

0 commit comments

Comments
 (0)