fix: add global or import scripts into DOM#1030
Conversation
|
Visit the preview URL for this PR (updated for commit 39974db): https://react-kitchen-sink-dev--pr1030-1027-add-global-and-mit9l9lq.web.app (expires Mon, 03 Mar 2025 13:13:52 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 6267897ade2ba783b6db70a53a60fc3946d625e9 |
|
| const globalBlock = screen.global; | ||
| const importedScripts = screen.importedScripts; | ||
|
|
||
| const isScriptExist = document.getElementById("custom-scope-script"); |
There was a problem hiding this comment.
This needs to be unique per screen.
| `; | ||
|
|
||
| if (isScriptExist) { | ||
| isScriptExist.textContent = jsString; |
There was a problem hiding this comment.
This does not rerun the script, you need to remove the node and reinsert it.
| if (has(invokableObj, "ensemble")) { | ||
| const tempEnsemble = get(invokableObj, "ensemble") as { | ||
| [key: string]: unknown; | ||
| }; | ||
| (window as unknown as InvokableWindow).ensemble = omitBy( | ||
| tempEnsemble, | ||
| isUndefined, | ||
| ); | ||
| } |
There was a problem hiding this comment.
This can be set once - most of the functions in ensemble API do not require any screen params. The only thing would be the modal context, which can be passed in as an argument.
|
|
||
| return (scriptToExecute, context) => { | ||
| with (context) { | ||
| return eval('(' + scriptToExecute.toString() + ')()'); |
There was a problem hiding this comment.
This can just be scriptToExecute()
Describe your changes
Add global or import scripts into DOM to reduce the load on buildEvaluateFunction
Screenshots [Optional]
Issue ticket number and link
Closes #1027
Checklist before requesting a review
pnpm changeset add