-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] dcc.Location not honoring refresh=False for dynamic layouts starting with dash v 1.13 #1346
Comments
@giftculture - Thanks for reporting! It is possible for you to create a very simple, standalone example that reproduces this issue? We haven't seen this issue come up yet and our tests didn't fail, so we're not quite sure where this issue might lie yet. |
Hello! A simple example is included here, let me know if you have any issues reading it |
@chriddyp Not sure if you got notification for my post above, but I attached a zipped tar file that includes a simple example |
Has this been addressed at all or is it still a bug in 1.19.0? I think my callback is basically going into an infinite loop. |
Also experiencing a similar issue, page reloads on every callback firing and resets layout to initial state. |
Any update on the issue . Is there a work around ? |
I think the issue is with |
I'll note after experimenting a bit that the infinite loop bug is only triggered if the id attribute of the dcc.Location class is set to 'url' - it doesn't occur if the attribute is set to a different string than 'url'
Also, this bug is still present in Dash 2.0.0 |
Here is another minimal example
|
Here is another related issue. If """
Try alternating between pg1 and pg2 by clicking on the links
Try it with dcc.Location only in page2, then try it with dcc.Location only in app.py
"""
from dash import Dash, dcc, html, Input, Output, register_page, page_container
page1 = html.Div("PAGE 1 CONTENT")
page2 = html.Div(
[
html.Div("Page 2"),
# Navigation is buggy when dcc.Location is here
dcc.Location(id="url", refresh=False),
html.Div( id="pg2-output"),
],
)
app = Dash(__name__, suppress_callback_exceptions=True, use_pages=True, pages_folder="")
register_page("page2", layout=page2)
register_page("page1", path="/", layout=page1)
app.layout = html.Div(
[
# Navigation works as expected when dcc.Location is in app.py
# dcc.Location(id="url", refresh=False),
dcc.Link("Go to Page 1", href="/"),
html.Br(),
dcc.Link("Go to Page 2", href="/page2"),
html.Div(page_container)
]
)
@app.callback(
Output("pg2-output", "children"),
Input("url", "href")
)
def update(href):
return href
if __name__ == "__main__":
app.run_server(debug=True)
|
Thanks for providing the MWE @AnnMarieW . I am also seeing this bug in a larger project and was not able to isolate it so far, the MWE helps a lot. Has there been any progress on finding what causes this? I tried to look into it but my understanding of react is limited. My current working hypothesis is that
But maybe this deserves it's own bug/issue. There is no problem with refreshing as in this title. Also - while i am not an expert on dash - I am quite sure the label And it basically breaks navigation when using the pages feature. |
Currently, if the component is not mounted (e.g. because on a different page), the component will still receive the change event and the `onLocationChange` callback changes its props via `this.props.setProps` with the itempath from ('_dashprivate_path') in the DOM. The object, however, is not on the dom and a random other DOM element is assigned the changed props. The PR deregisters the event listeners of the component is unmounted. They will be added again via `componentDidMount` anyways if the component is mounted again. fixes plotly#1346
Currently, if the component is not mounted (e.g. because on a different page), the component will still receive the change event and the `onLocationChange` callback changes its props via `this.props.setProps` with the itempath from ('_dashprivate_path') in the DOM. The object, however, is not on the dom and a random other DOM element is assigned the changed props. The PR deregisters the event listeners of the component is unmounted. They will be added again via `componentDidMount` anyways if the component is mounted again. fixes plotly#1346
Thank you so much for helping improve the quality of Dash!
We do our best to catch bugs during the release process, but we rely on your help to find the ones that slip through.
Describe your context
Please provide us your environment so we can easily reproduce the issue.
Describe the bug
Starting with dash v 1.13, dcc.Location isn't respecting refresh=False for dynamic layouts, it is getting triggered over and over again
index.py
cumulative_pnl.py looks like:
In Dash 1.13, it seems to get stuck in an infinite loop, triggering over and over, with the datetime continually updating. If I comment out dcc.Location, I get the expected behavior, so there's something going on with dcc.Location - it appears to not be respecting refresh=False
Expected behavior
Layout renders one time, with the current datetime (works under dash 1.12)
Each time I go to /apps/cumulative_pnl, the return_layout function is invoked and my layout renders once, showing the datetime as of page load
The text was updated successfully, but these errors were encountered: