vite-plugin-dynamic-base icon indicating copy to clipboard operation
vite-plugin-dynamic-base copied to clipboard

fix: failed getElementById in @micro-zoe/micro-app proxy sandbox mode

Open chenhuang444 opened this issue 1 year ago • 2 comments

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

chenhuang444 avatar Dec 17 '24 14:12 chenhuang444

So we are using @micro-zoe/micro-app (https://github.com/jd-opensource/micro-app) for our micro frontend project, and we came across this issue:

They strip the content of inline scripts and execute it in a Proxied environment, which does not have access to the original <script> tag and data-src attribute.

Submitting a fix for this problem. Also I believe this make the plugin more robust as it does not rely on a getElementById call at runtime

chenhuang444 avatar Dec 17 '24 14:12 chenhuang444

There is also an issue with replaceInStringLiteral function in that replacing with stringLiteral.value will unescape double quotes and the such. for example

const styleString = "@charset \"UTF-8\";cursor: url(/__vite_dynamic_public_path__/assets/cursor.svg);"

will have the raw as "@charset \"UTF-8\";cursor: url(/__vite_dynamic_public_path__/assets/cursor.svg);" and value as @charset "UTF-8";cursor: url(/__vite_dynamic_public_path__/assets/cursor.svg);

The original method would transform the output into:

const styleString = "@charset "UTF-8";cursor: url(" + window.SOMETHING + "/assets/cursor.svg);"

which is broken due to the unescaped double quotes

chenhuang444 avatar Dec 17 '24 18:12 chenhuang444