Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vdonato
Copy link
Collaborator

@vdonato vdonato commented Jun 18, 2025

Describe your changes

In some of our deployments of Streamlit in Snowflake, we need to be able to proxy requests
to fetch custom component assets through another service (for authentication / origin reasons)
but still rely on the Streamlit server's endpoints to server custom component assets. This can't
be done today as we explicitly disallow setting both a url and path for a component at once,
but it seems like this restriction was put in place at the time because we didn't expect people
to ever want to do this. Now that we have a good reason to do so, it shouldn't hurt to remove
the code preventing it.

We also add a new server.customComponentBaseUrlPath config option that makes it
possible to automatically set URLs for a component to be
{server.customComponentBaseUrlPath}/{component_name} when set. For now, the new
config option is kept hidden so that the API can change freely if needed, but if we see demand
from elsewhere in the community to do this kind of thing, we may publicly expose it.

Testing Plan

  • Unit Tests (JS and/or Python)
    • Updated both JS and Python tests where needed

Contribution License Agreement

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

@snyk-io
Copy link
Contributor

snyk-io bot commented Jun 18, 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
Contributor

github-actions bot commented Jun 18, 2025

✅ PR preview is ready!

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

@vdonato vdonato force-pushed the vdonato/vNext-custom-components-support branch from 2e32281 to 2b92d2a Compare June 19, 2025 03:56
@vdonato vdonato added security-assessment-completed Security assessment has been completed for PR impact:internal PR changes only affect internal code change:feature PR contains new feature or enhancement implementation labels Jun 19, 2025
@vdonato vdonato force-pushed the vdonato/vNext-custom-components-support branch from 2b92d2a to 3793575 Compare June 19, 2025 04:07
@vdonato vdonato marked this pull request as ready for review June 20, 2025 18:25
@vdonato vdonato force-pushed the vdonato/vNext-custom-components-support branch from cf6ec0d to 3793575 Compare June 20, 2025 18:56
@sfc-gh-bnisco sfc-gh-bnisco requested a review from Copilot June 20, 2025 20:33
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 PR removes the mutual exclusivity restriction between path and url in custom components, adds a hidden server.customComponentBaseUrlPath config option for automatically generating component URLs, and updates tests and the frontend test suite to cover the new behavior.

  • Remove the “either-or” check so both path and url can be set; url now takes precedence
  • Introduce a hidden server.customComponentBaseUrlPath config option and wire it into declare_component
  • Update Python and TS tests to reflect the new semantics and add coverage for base-path URL generation

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/streamlit/config.py Add hidden server.customComponentBaseUrlPath option
lib/streamlit/components/v1/component_registry.py Wire in customComponentBaseUrlPath to set url
lib/streamlit/components/types/base_custom_component.py Remove exclusive-or check for path/url
lib/tests/streamlit/config_test.py Add new config key to expected list
lib/tests/streamlit/components_test.py Update tests for both-allowed behavior and new URL
frontend/lib/src/components/widgets/CustomComponent/...tsx Add TS test for URL fallback from registry
Comments suppressed due to low confidence (2)

lib/streamlit/components/types/base_custom_component.py:44

  • Add or update the docstring/comments above this __init__ to describe the new behavior when both path and url are provided, clarifying that url now takes precedence rather than raising an error.
        if path is None and url is None:

lib/tests/streamlit/components_test.py:171

  • Add a test under a non-empty server.customComponentBaseUrlPath config to verify that when both path and an explicit url argument are provided, the explicit url wins over the base-path setting.
    def test_both_path_and_url_ok(self):

Copy link
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a comment

Choose a reason for hiding this comment

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

Chatted offline, LGTM.

@vdonato vdonato merged commit cae9b46 into develop Jun 24, 2025
68 checks passed
@vdonato vdonato deleted the vdonato/vNext-custom-components-support branch June 24, 2025 19:45
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 security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants