repl
repl copied to clipboard
Bug:es-module-shims cause CSS inject code failed
When use https://sfc.vuejs.org/ sometimes css is not in the output iframe page.
I trace the code and find when code use window.__css__,it is still nothing
this is a problem with es-module-shims witch causes normal script run as module script in twice.
here is a demo:
<html>
<head>
<meta charset="utf-8">
<script async="" src="https://unpkg.com/[email protected]/dist/es-module-shims.wasm.js"></script>
</head>
<body>
<script>
async function start() {
const scripts = [
`console.log('script run!!!!!! but run twice')`
]
for(let script of scripts) {
const scriptNode = document.createElement('script')
scriptNode.setAttribute('type', 'module')
scriptNode.innerHTML = script
document.head.appendChild(scriptNode)
}
}
setTimeout(() => start(), 2000)
</script>
<div>this is a test</div>
<div id="app"></div>
</body>
</html>
you will see two log with script run!!!!!! but run twice
Thus window.__css__ = 'xxxxxxxx' code was covered by window.__css__ = ''(run twice)
I don't know how to fix this
Maybe remove es-module-shims.js?or maybe change the original code to make sure curCode in a module or a normal script