-
Notifications
You must be signed in to change notification settings - Fork 4k
Support proxying requests to fetch custom component assets #11698
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
Conversation
🎉 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) |
✅ PR preview is ready!
|
2e32281 to
2b92d2a
Compare
2b92d2a to
3793575
Compare
cf6ec0d to
3793575
Compare
There was a problem hiding this 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
pathandurlcan be set;urlnow takes precedence - Introduce a hidden
server.customComponentBaseUrlPathconfig option and wire it intodeclare_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 bothpathandurlare provided, clarifying thaturlnow 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.customComponentBaseUrlPathconfig to verify that when bothpathand an expliciturlargument are provided, the expliciturlwins over the base-path setting.
def test_both_path_and_url_ok(self):
sfc-gh-bnisco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chatted offline, LGTM.
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
urlandpathfor 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.customComponentBaseUrlPathconfig option that makes itpossible to automatically set URLs for a component to be
{server.customComponentBaseUrlPath}/{component_name}when set. For now, the newconfig 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
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.