Skip to content

Conversation

@sagardspeed2
Copy link
Contributor

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

  • I have performed a self-review of my code
  • I have added tests
  • I have added a changeset pnpm changeset add
  • I have added example usage in the kitchen sink app

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2025

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

@sagardspeed2 sagardspeed2 self-assigned this Feb 8, 2025
@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2025

⚠️ No Changeset found

Latest commit: 39974db

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

const globalBlock = screen.global;
const importedScripts = screen.importedScripts;

const isScriptExist = document.getElementById("custom-scope-script");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be unique per screen.

`;

if (isScriptExist) {
isScriptExist.textContent = jsString;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not rerun the script, you need to remove the node and reinsert it.

Comment on lines +54 to +62
if (has(invokableObj, "ensemble")) {
const tempEnsemble = get(invokableObj, "ensemble") as {
[key: string]: unknown;
};
(window as unknown as InvokableWindow).ensemble = omitBy(
tempEnsemble,
isUndefined,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() + ')()');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be scriptToExecute()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve performance with large global scripts

2 participants