Skip to content

Layout as list of components does not work with Dash Pages page_container #2924

Closed
@antonymilne

Description

@antonymilne

Describe your context

dash                       2.17.1
dash_ag_grid               31.2.0
dash-bootstrap-components  1.6.0
dash-core-components       2.0.0
dash-html-components       2.0.0
dash-mantine-components    0.12.1
dash-table                 5.0.0
dash-testing-stub          0.0.2

Describe the bug

#2795 enabled you to pass a list of components to app.layout. However, this does not work with page_container.

import dash

from dash import Dash, html, page_container

app = Dash(__name__, use_pages=True, pages_folder="")
dash.register_page("/", layout=html.H1("Hello"))
app.layout = [page_container, html.H2("Stuff")]
# These work ok:
# app.layout = page_container
# app.layout = html.Div([page_container, html.H2("Stuff")])

app.run()

The first request will give the following exception:

Exception: `dash.page_container` not found in the layout

Subsequent page refreshes are ok because this check only occurs on the first request.

The problem is that the following check is failing:

dash/dash/dash.py

Line 2257 in bbd013c

if _ID_CONTENT not in self.validation_layout:

The reason for that is as follows:

assert "a" in html.Div(html.Div(id="a")) # passes
assert "a" in html.Div([html.Div(id="a")]) #passes
assert "a" in html.Div([[html.Div(id="a")]]) # FAILS - this is the relevant case here

As with #2905 probably the easiest solution is to wrap the layout in html.Div in this case so that the check passes:

assert "a" in html.Div([html.Div([html.Div(id="a")])]) # passes

Note that while #2905 is very similar it looks like the proposed fix #2915 will not solve this case. Given these two very similar issues, maybe there's a better elsewhere that would fix both (and any other similar undiscovered issues) simultaneously?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething brokengood first issuesuitable for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions