-
-
Notifications
You must be signed in to change notification settings - Fork 144
callbacks watching dcc.Location's url.pathname fire twice on first page load #138
Comments
This may be related to plotly/dash#133 and plotly/dash-renderer#24. (See specifically @chriddyp's comment here plotly/dash#133 (comment)). We addressed it for our Dash applications by adding |
Yeah, this is sort of "intentional" although it is confusing. I think I explained it in my comments but another solution is to return with the loading state with:
I'm going to close this for now as this behaviour is pretty deeply ingrained in dash's front-end. |
Yep for sure. I hadn't seen the discussion where you explain that, but it makes sense. I think my preference for handling it (but obviously depends on the context) is to throw an exception for that request. If #190 goes in, then it's an even cleaner strategy. |
So I bumped into this double triggering of callbacks and worked around it with an intermediate callback that did nothing. I didn't even need to raise Perhaps my attached simple example will be of use to someone: location-double-callback-workaround.py Slightly related to this, I was messing around with query strings to perform actions, and found that I needed to change Edit: I should have emphasised that I had more than one callback listening for changes to |
When a callback targets dcc.Location's url.pathname, on the first page load (but not on the app load), I'm seeing that the callback is fired twice. The first time the
pathname
Input gets the valueNone
, then on the second time it gets the correct current value from the URL.Most of the time I'm comparing
pathname
against some string, so nothing bad happens and then the callback fires again and behaves correctly. However I can certainly imagine a scenario when the assumption thatpathname
is a string will make things break. Not to mention it's a little confusing when debugging.The text was updated successfully, but these errors were encountered: