Skip to content

fix: gradio_api path in mount_gradio_app#12803

Open
shandowc wants to merge 4 commits intogradio-app:mainfrom
shandowc:fix/mount-gradio-app
Open

fix: gradio_api path in mount_gradio_app#12803
shandowc wants to merge 4 commits intogradio-app:mainfrom
shandowc:fix/mount-gradio-app

Conversation

@shandowc
Copy link

@shandowc shandowc commented Jan 21, 2026

Description

When mounting a Gradio app to a FastAPI application at a subpath using gr.mount_gradio_app(), custom component assets (CSS and JS files) return 404 errors because the frontend requests don't include the mount path prefix.

Closes: #12802

AI Disclosure

We encourage the use of AI tooling in creating PRs, but the any non-trivial use of AI needs be disclosed. E.g. if you used Claude to write a first draft, you should mention that. Trivial tab-completion doesn't need to be disclosed. You should self-review all PRs, especially if they were generated with AI.

  • I used AI to write a first draft
  • I did not use AI

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Testing and Formatting Your Code

  1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests: bash scripts/run_backend_tests.sh

  2. Please run these bash scripts to automatically format your code: bash scripts/format_backend.sh, and (if you made any changes to non-Python files) bash scripts/format_frontend.sh

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug where custom component assets (CSS and JS files) return 404 errors when a Gradio app is mounted at a subpath using gr.mount_gradio_app(). The issue occurred because the frontend was incorrectly constructing the API URL using JavaScript's URL constructor, which doesn't properly preserve the mount path.

Changes:

  • Introduced a new get_api_url() helper function that correctly concatenates the root path and API prefix
  • Replaced direct new URL(config.api_prefix, config.root) calls with the new helper function in two locations within the AppTree class

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

shandowc and others added 2 commits January 22, 2026 09:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@shandowc
Copy link
Author

@freddyaboulton could you plz review this pr?

@Florian-BACHO
Copy link

Hi,

Any update on this PR?
We would like to migrate to Gradio 6 but this issue is blocking us.

@freddyaboulton
Copy link
Collaborator

Will take a look! Sorry for the delay. We were waiting on #12879

# Conflicts:
#	js/core/src/init.test.skip.ts
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.

Custom component assets return 404 when Gradio app is mounted at a subpath using mount_gradio_app

4 participants