Skip to content
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

Wrapper function to avoid polluting global namespace #2362

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- `custom_spinner` enables using a custom component for loading messages instead of built-in spinners
- `display` overrides the loading status with options for "show," "hide," or "auto"

## Fixed

- [#2362](https://github.com/plotly/dash/pull/2362) Global namespace not polluted any more when loading clientside callbacks.

## [2.16.1] - 2024-03-06

## Fixed
Expand Down
8 changes: 5 additions & 3 deletions dash/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,11 @@ def add_context(*args, **kwargs):


_inline_clientside_template = """
var clientside = window.dash_clientside = window.dash_clientside || {{}};
var ns = clientside["{namespace}"] = clientside["{namespace}"] || {{}};
ns["{function_name}"] = {clientside_function};
(function() {{
var clientside = window.dash_clientside = window.dash_clientside || {{}};
var ns = clientside["{namespace}"] = clientside["{namespace}"] || {{}};
ns["{function_name}"] = {clientside_function};
}})();
"""


Expand Down
4 changes: 4 additions & 0 deletions tests/integration/clientside/test_clientside.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def update_output(value):
dash_duo.wait_for_text_to_equal("#output-serverside", 'Server says "hello world"')
dash_duo.wait_for_text_to_equal("#output-clientside", 'Client says "hello world"')

assert dash_duo.driver.execute_script("return 'dash_clientside' in window")
assert dash_duo.driver.execute_script("return !('clientside' in window)")
assert dash_duo.driver.execute_script("return !('ns' in window)")


def test_clsd002_chained_serverside_clientside_callbacks(dash_duo):
app = Dash(__name__, assets_folder="assets")
Expand Down