Skip to content

Commit

Permalink
Merge pull request #2362 from frnhr/clientside-template-wrap
Browse files Browse the repository at this point in the history
Wrapper function to avoid polluting global namespace
  • Loading branch information
T4rk1n committed Mar 29, 2024
2 parents f7f8fb4 + 0b1a0f3 commit 230d664
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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

0 comments on commit 230d664

Please sign in to comment.