Skip to content

Commit

Permalink
fix(shadow): 修复DOMParser渲染html元素丢失沙箱上下文的问题 #921 (#928)
Browse files Browse the repository at this point in the history
Co-authored-by: gadzanmai <[email protected]>
  • Loading branch information
gadzan and lx-gadzanmai authored Dec 8, 2024
1 parent be705d6 commit a6ea729
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/wujie-core/src/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ function renderTemplateToHtml(iframeWindow: Window, template: string): HTMLHtmlE
const parsedDocument = parser.parseFromString(template, "text/html");

// 无论 template 是否包含html,documentElement 必然是 HTMLHtmlElement
let html = parsedDocument.documentElement as HTMLHtmlElement;
const parsedHtml = parsedDocument.documentElement as HTMLHtmlElement;
const sourceAttributes = parsedHtml.attributes;
let html = document.createElement("html");
html.innerHTML = template;
for (let i = 0; i < sourceAttributes.length; i++) {
html.setAttribute(sourceAttributes[i].name, sourceAttributes[i].value);
}
// 组件多次渲染,head和body必须一直使用同一个来应对被缓存的场景
if (!alive && execFlag) {
html = replaceHeadAndBody(html, head, body);
Expand Down

0 comments on commit a6ea729

Please sign in to comment.