Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CrossOriginWorkerMaker to cache the blob URL #7571

Merged
merged 4 commits into from Mar 8, 2024

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Feb 29, 2024

Description

There is a bug that multiple SharedWorker-s are created for the same site when the Lite's worker script (webworker.js) is loaded from a different origin through CrossOriginWorkerMaker.
It is because this part is called every time a new worker is created.
To avoid it, caching mechanism is introduced in this PR.

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 29, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website building...
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/4b090da8b8ccd982cc4bd95efb443a1e44848509/gradio-4.20.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@4b090da8b8ccd982cc4bd95efb443a1e44848509#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 29, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/wasm minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix CrossOriginWorkerMaker to cache the blob URL

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@whitphx whitphx added the gradio-lite Related to the @gradio/lite library label Feb 29, 2024
@whitphx whitphx marked this pull request as ready for review March 1, 2024 01:51
@aliabd
Copy link
Collaborator

aliabd commented Mar 3, 2024

@whitphx the changes look good, but how should I test this?

@whitphx
Copy link
Member Author

whitphx commented Mar 4, 2024

@aliabd
The points are

  • Serve the Lite scripts and a web site from different origins.
  • Run multiple Lite apps in a browser.
  • Confirm only one SharedWorker is created.

For example,

  1. Build Lite and serve the scripts from one port of localhost, e.g. from localhost:8000.
  2. Import the served script (http://localhost:8000/path/to/lite.js) from another website (e.g. js/_website) and embed a Lite app enabling the SharedWorker mode.
  3. Serve the website from a different port e.g. localhost:5173.
  4. Open the website e.g. http://localhost:5173/path/to/page in Chrome in multiple tabs, and confirm the Lite app is working.
  5. Open chrome://inspect/#workers and confirm only one SharedWorker is created.

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Looks great and seem to work well as far as I can test! Thanks @whitphx!

Could we change these functions and variables to use snake_case like the rest of the library?

@whitphx
Copy link
Member Author

whitphx commented Mar 8, 2024

@pngwn Updated 👍

@whitphx whitphx requested a review from pngwn March 8, 2024 11:12
Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks again @whitphx!

@abidlabs
Copy link
Member

abidlabs commented Mar 8, 2024

I'll go ahead and merge this in to get it out for the release.

cc @aliabd as well for visibility

@abidlabs abidlabs merged commit 2edba13 into main Mar 8, 2024
7 of 8 checks passed
@abidlabs abidlabs deleted the cache-wasm-worker-blob-url branch March 8, 2024 20:03
@pngwn pngwn mentioned this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gradio-lite Related to the @gradio/lite library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants