Skip to content

Make document basepath configurable via window variable#11537

Merged
vdonato merged 5 commits intodevelopfrom
vdonato/configurable-window-basepath
Jun 7, 2025
Merged

Make document basepath configurable via window variable#11537
vdonato merged 5 commits intodevelopfrom
vdonato/configurable-window-basepath

Conversation

@vdonato
Copy link
Copy Markdown
Collaborator

@vdonato vdonato commented Jun 5, 2025

Describe your changes

In #11378, we left some TODOs to come back and fix page URL handling for multipage
apps in the world where we configure the client to hit a different origin for the Streamlit
server from the one that we fetched our index.html from. This PR addresses these issues
by defining a new MAIN_PAGE_BASE_URL field in the __streamlit object which lets us
explicitly specify what the base URL for the document (that is, the URL of the main page of
the app) should be.

Note that this change will also make it possible to fix the annoying issue where initial
healthcheck requests hit a 404 when navigating directly to a subpage of a multipage
app in the pure OSS world, but we don't do so in this PR as it'll also require us to change
how our static asset handler works to no longer serve a truly static index.html but
dynamically set some pieces of it, which would take a nontrivial amount of additional
effort.

Testing Plan

  • Unit Tests (JS and/or Python)
    • Adjusted JS unit tests
  • Any manual testing needed?
    • Need to do some manual integration tests to verify that this works as expected
      when window.__streamlit.MAIN_PAGE_BASE_URL is set.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@vdonato vdonato added security-assessment-completed impact:internal PR changes only affect internal code change:feature PR contains new feature or enhancement implementation labels Jun 5, 2025
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Jun 5, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 5, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11537/streamlit-1.45.1-py3-none-any.whl
🕹️ Preview app pr-11537.streamlit.app (☁️ Deploy here if not accessible)

@vdonato vdonato force-pushed the vdonato/configurable-window-basepath branch from c519a7e to 726f150 Compare June 5, 2025 22:53
@vdonato vdonato force-pushed the vdonato/configurable-window-basepath branch from 726f150 to 38dd9d8 Compare June 5, 2025 23:06
@vdonato vdonato force-pushed the vdonato/configurable-window-basepath branch from 38dd9d8 to 5e7fdcb Compare June 5, 2025 23:59
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@lukasmasuch lukasmasuch requested a review from Copilot June 6, 2025 08:56
Copy link
Copy Markdown
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

Introduces a new DOCUMENT_BASE_URL window variable and refactors URI parsing to handle multipage apps when the document base path differs from the asset host.

  • Add DOCUMENT_BASE_URL to the global Streamlit window object.
  • Rename and centralize URI parsing logic (getBaseUriPartsparseUriIntoBaseParts).
  • Update App and connection utilities/tests to respect DOCUMENT_BASE_URL for navigation.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
frontend/utils/src/types/index.ts Add DOCUMENT_BASE_URL field to StreamlitWindowObject.
frontend/connection/src/utils.ts Rename getBaseUriParts to parseUriIntoBaseParts.
frontend/connection/src/utils.test.ts Update tests to use parseUriIntoBaseParts.
frontend/connection/src/index.ts Export parseUriIntoBaseParts.
frontend/connection/src/DoInitPings.tsx Use parseUriIntoBaseParts for host config.
frontend/app/src/App.tsx Branch on DOCUMENT_BASE_URL for history handling.
frontend/app/src/App.test.tsx Add tests covering DOCUMENT_BASE_URL scenarios.
Comments suppressed due to low confidence (3)

frontend/utils/src/types/index.ts:44

  • [nitpick] Consider adding a brief comment explaining the semantics of DOCUMENT_BASE_URL, e.g., that it should point to the app's root URL for multipage routing.
DOCUMENT_BASE_URL?: string

frontend/connection/src/utils.ts:25

  • [nitpick] Add a JSDoc comment for parseUriIntoBaseParts describing its behavior (especially the trimming of leading/trailing slashes and default port assignment).
export function parseUriIntoBaseParts(url?: string): URL {

frontend/app/src/App.tsx:1082

  • [nitpick] pathname is reused in multiple scopes — consider renaming to something like documentBasePath to clarify its origin when branching on DOCUMENT_BASE_URL.
let pathname

@vdonato vdonato merged commit db5f756 into develop Jun 7, 2025
37 of 38 checks passed
@vdonato vdonato deleted the vdonato/configurable-window-basepath branch June 7, 2025 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:internal PR changes only affect internal code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants