Skip to content

Commit 8c76cd0

Browse files
committed
Fix async/dynamic resources loading.
1 parent 07f44ec commit 8c76cd0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

dash/dash.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -809,17 +809,13 @@ def serve_dist(self):
809809
libraries = flask.request.get_json()
810810
dists = []
811811
for dist_type in ("_js_dist", "_css_dist"):
812-
resources = [
813-
resource
814-
for resource in ComponentRegistry.get_resources(dist_type, libraries)
815-
if not resource.get("async") and not resource.get("dynamic")
816-
]
817-
srcs = self._collect_and_register_resources(resources)
812+
resources = ComponentRegistry.get_resources(dist_type, libraries)
813+
srcs = self._collect_and_register_resources(resources, False)
818814
for src in srcs:
819815
dists.append(dict(type=dist_type, url=src))
820816
return flask.jsonify(dists)
821817

822-
def _collect_and_register_resources(self, resources):
818+
def _collect_and_register_resources(self, resources, include_async=True):
823819
# now needs the app context.
824820
# template in the necessary component suite JS bundles
825821
# add the version number of the package as a query parameter
@@ -848,6 +844,8 @@ def _relative_url_path(relative_package_path="", namespace=""):
848844
srcs = []
849845
for resource in resources:
850846
is_dynamic_resource = resource.get("dynamic", False)
847+
is_async = resource.get("async") is not None
848+
excluded = not include_async and is_async
851849

852850
if "relative_package_path" in resource:
853851
paths = resource["relative_package_path"]
@@ -859,15 +857,15 @@ def _relative_url_path(relative_package_path="", namespace=""):
859857

860858
self.registered_paths[resource["namespace"]].add(rel_path)
861859

862-
if not is_dynamic_resource:
860+
if not is_dynamic_resource and not excluded:
863861
srcs.append(
864862
_relative_url_path(
865863
relative_package_path=rel_path,
866864
namespace=resource["namespace"],
867865
)
868866
)
869867
elif "external_url" in resource:
870-
if not is_dynamic_resource:
868+
if not is_dynamic_resource and not excluded:
871869
if isinstance(resource["external_url"], str):
872870
srcs.append(resource["external_url"])
873871
else:

tests/integration/test_generation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ def test_gene001_simple_callback(dash_duo):
5656
def test_gene002_arbitrary_resources(dash_duo):
5757
app = Dash(__name__)
5858

59-
app.layout = Div([Button("Click", id="btn"), Div(id="container")])
59+
app.layout = Div(
60+
[
61+
Button("Click", id="btn"),
62+
Div(id="container"),
63+
MyStandardComponent(),
64+
]
65+
)
6066

6167
@app.callback(Output("container", "children"), [Input("btn", "n_clicks")])
6268
def update_container(n_clicks):

0 commit comments

Comments
 (0)