You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I can tell, #1941 only partially fixed the logic that determined which SW gets posted to when you call messageSW(). I'm seeing that it will post to the waiting SW (like I would expect) when you visit a page and an updated version of a SW gets registered for the first time, but if you revisit the page while that version of the SW is still waiting and then try calling messageSW(), it will end up posting to the active (older) SW instead.
I'm assuming that this is a bug, but if it's not, I guess I'm just confused as to why the behavior is different in those scenarios.
I also wonder whether it's a sign that exposing messageSW() without any guarantees about which SW will get posted to is something we should clean up in the interface—since maybe there are scenarios in which you need explicit control over posting to the active SW vs. waiting, perhaps letting developers explicitly state which SW they want via an optional parameter would make sense.
The text was updated successfully, but these errors were encountered:
I do think this was a bug since the intent of getSW() (which messageSW() uses under the hood) is to resolve to the most recently registered version of the SW that matches the script URL. In the case of a SW waiting before registration, it fits that definition, and also seems to meet your use case.
Note, in cases where you want to message a SW other than the one returned by getSW(), you can use the top-level messageSW(sw, data) method, since it lets you pick what SW to message.
Library Affected:
workbox-window
You can reproduce this by remixing and experimenting with https://glitch.com/edit/#!/w-w-experiment?path=public/index.html
As far as I can tell, #1941 only partially fixed the logic that determined which SW gets posted to when you call
messageSW()
. I'm seeing that it will post to thewaiting
SW (like I would expect) when you visit a page and an updated version of a SW gets registered for the first time, but if you revisit the page while that version of the SW is stillwaiting
and then try callingmessageSW()
, it will end up posting to theactive
(older) SW instead.I'm assuming that this is a bug, but if it's not, I guess I'm just confused as to why the behavior is different in those scenarios.
I also wonder whether it's a sign that exposing
messageSW()
without any guarantees about which SW will get posted to is something we should clean up in the interface—since maybe there are scenarios in which you need explicit control over posting to theactive
SW vs.waiting
, perhaps letting developers explicitly state which SW they want via an optional parameter would make sense.The text was updated successfully, but these errors were encountered: