Skip to content

Commit 230d664

Browse files
authored
Merge pull request #2362 from frnhr/clientside-template-wrap
Wrapper function to avoid polluting global namespace
2 parents f7f8fb4 + 0b1a0f3 commit 230d664

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1414
- `custom_spinner` enables using a custom component for loading messages instead of built-in spinners
1515
- `display` overrides the loading status with options for "show," "hide," or "auto"
1616

17+
## Fixed
18+
19+
- [#2362](https://github.com/plotly/dash/pull/2362) Global namespace not polluted any more when loading clientside callbacks.
20+
1721
## [2.16.1] - 2024-03-06
1822

1923
## Fixed

dash/_callback.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,11 @@ def add_context(*args, **kwargs):
502502

503503

504504
_inline_clientside_template = """
505-
var clientside = window.dash_clientside = window.dash_clientside || {{}};
506-
var ns = clientside["{namespace}"] = clientside["{namespace}"] || {{}};
507-
ns["{function_name}"] = {clientside_function};
505+
(function() {{
506+
var clientside = window.dash_clientside = window.dash_clientside || {{}};
507+
var ns = clientside["{namespace}"] = clientside["{namespace}"] || {{}};
508+
ns["{function_name}"] = {clientside_function};
509+
}})();
508510
"""
509511

510512

tests/integration/clientside/test_clientside.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def update_output(value):
3535
dash_duo.wait_for_text_to_equal("#output-serverside", 'Server says "hello world"')
3636
dash_duo.wait_for_text_to_equal("#output-clientside", 'Client says "hello world"')
3737

38+
assert dash_duo.driver.execute_script("return 'dash_clientside' in window")
39+
assert dash_duo.driver.execute_script("return !('clientside' in window)")
40+
assert dash_duo.driver.execute_script("return !('ns' in window)")
41+
3842

3943
def test_clsd002_chained_serverside_clientside_callbacks(dash_duo):
4044
app = Dash(__name__, assets_folder="assets")

0 commit comments

Comments
 (0)