Skip to content

Commit 6c1ac56

Browse files
author
huangchenbj
committed
fix: failed getElementById in @micro-zoe/micro-app proxy sandbox mode
since data-src is a non-standard attribute, micro-zoe/micro-app does not do anything about it during their js sandbox processing. this causes legayPolyfill to fail
1 parent d1cb4ed commit 6c1ac56

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/core/transform.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,23 @@ export function transformLegacyHtml(code: string, options: TransformOptions) {
5050
content = replaceImport(publicPath, content)
5151
const document = parse(content, { comment: true })
5252
const legacyPolyfill = document.getElementById('vite-legacy-polyfill')
53+
const legacyPolyfillSrc = legacyPolyfill?.getAttribute('src')
54+
55+
const legacyEntry = document.getElementById('vite-legacy-entry')
56+
const legacyEntrySrc = legacyEntry?.getAttribute('data-src')
57+
5358
if (legacyPolyfill) {
54-
legacyPolyfill.setAttribute('data-src', legacyPolyfill.getAttribute('src'))
59+
legacyPolyfill.setAttribute('data-src', legacyPolyfillSrc)
5560
legacyPolyfill.removeAttribute('src')
5661
legacyPolyfill.innerHTML = `!(function() {
5762
var e = document.createElement('script')
58-
e.src = ${publicPath} + document.getElementById('vite-legacy-polyfill').getAttribute('data-src');
63+
e.src = ${publicPath} + "${legacyPolyfillSrc}";
5964
e.onload = function() {
60-
System.import(${publicPath}+document.getElementById('vite-legacy-entry').getAttribute('data-src'))
65+
System.import(${publicPath} + "${legacyEntrySrc}")
6166
};
6267
document.body.appendChild(e)
6368
})();`
6469
}
65-
const legacyEntry = document.getElementById('vite-legacy-entry')
6670
if (legacyEntry) {
6771
legacyEntry.innerHTML = ''
6872
}

0 commit comments

Comments
 (0)