Fix launch JavaScript function execution - #13642
Draft
dawoodkhan82 wants to merge 2 commits into
Draft
Conversation
Collaborator
🪼 branch checks and previews
Install Gradio from this PR pip install https://huggingface.co/buckets/gradio/pypi-previews/resolve/4acd2f60d9fd674323a7177e8774a75dfb0ea338/gradio-6.20.0-py3-none-any.whlInstall Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@4acd2f60d9fd674323a7177e8774a75dfb0ea338#subdirectory=client/python"Import Gradio JS Client from this PR via CDN import { Client } from "https://huggingface.co/buckets/gradio/npm-previews/resolve/4acd2f60d9fd674323a7177e8774a75dfb0ea338/browser.js"; |
Collaborator
🦄 change detectedThis Pull Request includes changes to the following packages.
|
dawoodkhan82
force-pushed
the
codex/issue-13636-launch-js
branch
from
July 20, 2026 16:27
de2d232 to
8d3d104
Compare
1 task
Contributor
There was a problem hiding this comment.
Pull request overview
Restore Gradio 5-era behavior where JavaScript passed via Blocks.launch(js=...) is actually executed on the client. The previous Gradio 6 approach injected the string into a <script> element without invoking function expressions, resulting in a silent no-op for common () => { ... } usage.
Changes:
- Move
config.jsexecution responsibility from SPA/App shells into@gradio/core’sBlockslifecycle (afterapp_tree.ready). - Add a shared executor (
execute_custom_js) that supports function expressions (sync/async) and statement-style JS. - Add unit tests and a changeset bump for affected packages.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| js/spa/src/Index.svelte | Removes direct <script> injection so launch(js=...) runs via core Blocks instead. |
| js/app/src/routes/[...catchall]/+page.svelte | Removes duplicate custom-JS injection in the SvelteKit app route. |
| js/core/src/custom_js.ts | Introduces execute_custom_js() to evaluate and invoke function-expression JS (with raw-JS fallback). |
| js/core/src/custom_js.test.ts | Adds Vitest coverage for function-expression, async function-expression, and raw JS execution. |
| js/core/src/Blocks.svelte | Executes js after app_tree.ready, with error logging, before setting ready and dispatching load events. |
| .changeset/clean-dogs-launch.md | Publishes patch releases for impacted packages to ship the regression fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Restore the Gradio 5 behavior for function strings passed to
Blocks.launch(js=...). The Gradio 6 frontend inserted the function expression into a script element but never called it. This adds a core executor that invokes sync and async function expressions while preserving raw JavaScript support, and runs it after the Blocks component tree is ready so Gradio's own page-title update cannot overwrite user code.Before / after Spaces
Closes: #13636
AI Disclosure
🎯 PRs Should Target Issues
This PR targets #13636. No overlapping open PR was found before submission.
Testing and Formatting Your Code
TEST_MODE=happy-dom pnpm exec vitest run js/core/src/custom_js.test.ts --config .config/vitest.config.ts --browser.enabled=falsepnpm --filter @self/app build --emptyOutDirpnpm --filter @self/spa build --emptyOutDirdocument.titleisLAUNCH-JS-RANwith no page errors (no Playwright test was added)bash scripts/format_frontend.sh(formatting completed; the repository-wide type check reports 15 unrelated existing errors injs/utils,js/markdown-code, andjs/preview)Minimal reproduction (the local file is untracked and was not committed):