dash-core-components icon indicating copy to clipboard operation
dash-core-components copied to clipboard

dcc.Location triggers once without any value for pathname

Open victornoel opened this issue 5 years ago • 3 comments

Since v1.9.1, it seems that the frontend triggers an update without any value for pathname (in the json request, there is not even the value key present) which results on the callbacks being called with None value for the pathname.

I tested with v1.9.0 (dash 1.10.0) and it works as expected.

I'm not sure if it is linked to the component itself or if it's dash 1.11.0 that introduces the problem…

victornoel avatar Apr 16 '20 14:04 victornoel

Thanks for the report! Can you include a simple app that exhibits the problem?

alexcjohnson avatar Apr 16 '20 21:04 alexcjohnson

@alexcjohnson here is one, if I open http://127.0.0.1:8050/ on the console it gives:

None
/

while when I use dash 1.10.0 with dash components 1.9.1, I get:

/
/
import dash
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash_html_components as html
from dash.dependencies import Input, Output


app = dash.Dash()

app.config.suppress_callback_exceptions = True
app.layout = html.Div([
    # represents the URL bar, doesn't render anything
    dcc.Location(id='url', refresh=False),

    # content will be rendered in this element
    dbc.Container(id='content', fluid=True),
])


@app.callback(Output('content', 'children'),
              [Input('url', 'pathname')])
def _content(pathname: str):
    print(pathname)
    return html.H1(children=f'pathname: {pathname}')


if __name__ == '__main__':
    app.run_server(debug=True)

victornoel avatar Apr 17 '20 10:04 victornoel

Has this issue been fixed? It's causing unexpected behavior for me also.

EDIT: Seems this is a long standing debate in the plotly community.

Is a relevant way to handle the initial None variable in pathname to do this as a callback?:

def _content(pathname):
    if pathname == None:
        return no_update, no_update

ksodipo avatar Jan 12 '21 08:01 ksodipo