Skip to content

Commit 6decb16

Browse files
committed
inline async tests + dc.context_callback deletion
1 parent 4ef7900 commit 6decb16

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

dash/dash-renderer/src/actions/callbacks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ async function handleClientside(
248248

249249
let returnValue = dc[namespace][function_name](...args);
250250

251+
delete dc.callback_context;
252+
251253
if (typeof returnValue?.then === 'function') {
252254
returnValue = await returnValue;
253255
}
@@ -270,8 +272,6 @@ async function handleClientside(
270272
throw e;
271273
}
272274
} finally {
273-
delete dc.callback_context;
274-
275275
// Setting server = client forces network = 0
276276
const totalTime = Date.now() - requestTime;
277277
const resources = {

tests/integration/clientside/test_clientside.py

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: UTF-8 -*-
22
from multiprocessing import Value, Lock
3-
import pytest
43

54
from dash import Dash, Input, Output, State, ClientsideFunction, ALL, html, dcc
65
from selenium.webdriver.common.keys import Keys
@@ -224,31 +223,6 @@ def test_clsd004_clientside_multiple_outputs(dash_duo):
224223
dash_duo.wait_for_text_to_equal(selector, expected)
225224

226225

227-
@pytest.mark.xfail(reason="Promises are now handled within Dash-Renderer")
228-
def test_clsd005_clientside_fails_when_returning_a_promise(dash_duo):
229-
app = Dash(__name__, assets_folder="assets")
230-
231-
app.layout = html.Div(
232-
[
233-
html.Div(id="input", children="hello"),
234-
html.Div(id="side-effect"),
235-
html.Div(id="output", children="output"),
236-
]
237-
)
238-
239-
app.clientside_callback(
240-
ClientsideFunction("clientside", "side_effect_and_return_a_promise"),
241-
Output("output", "children"),
242-
[Input("input", "children")],
243-
)
244-
245-
dash_duo.start_server(app)
246-
247-
dash_duo.wait_for_text_to_equal("#input", "hello")
248-
dash_duo.wait_for_text_to_equal("#side-effect", "side effect")
249-
dash_duo.wait_for_text_to_equal("#output", "output")
250-
251-
252226
def test_clsd006_PreventUpdate(dash_duo):
253227
app = Dash(__name__, assets_folder="assets")
254228

@@ -805,3 +779,53 @@ def callback(value):
805779
dash_duo.wait_for_text_to_equal("#clientside-div", "clientside-initial")
806780
lock.release()
807781
dash_duo.wait_for_text_to_equal("#serverside-div", "serverside-initial-deferred")
782+
783+
784+
def test_clsd018_clientside_inline_async_function(dash_duo):
785+
app = Dash(__name__)
786+
787+
app.layout = html.Div(
788+
[
789+
html.Div(id="input", children=["initial"]),
790+
html.Div(id="output-div"),
791+
]
792+
)
793+
794+
app.clientside_callback(
795+
"""
796+
async function(input) {
797+
return input + "-inline";
798+
}
799+
""",
800+
Output("output-div", "children"),
801+
Input("input", "children"),
802+
)
803+
804+
dash_duo.start_server(app)
805+
dash_duo.wait_for_text_to_equal("#output-div", "initial-inline")
806+
807+
808+
def test_clsd019_clientside_inline_promise(dash_duo):
809+
app = Dash(__name__)
810+
811+
app.layout = html.Div(
812+
[
813+
html.Div(id="input", children=["initial"]),
814+
html.Div(id="output-div"),
815+
]
816+
)
817+
818+
app.clientside_callback(
819+
"""
820+
function(inputValue) {
821+
return new Promise(function (resolve) {
822+
resolve(inputValue + "-inline");
823+
});
824+
}
825+
""",
826+
Output("output-div", "children"),
827+
Input("input", "children"),
828+
)
829+
830+
dash_duo.start_server(app)
831+
dash_duo.wait_for_text_to_equal("#output-div", "initial-nline")

0 commit comments

Comments
 (0)