Skip to content
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

messageSW inconsistency when you revisit a page with waiting SW #1957

Closed
jeffposnick opened this issue Mar 14, 2019 · 1 comment · Fixed by #1961
Closed

messageSW inconsistency when you revisit a page with waiting SW #1957

jeffposnick opened this issue Mar 14, 2019 · 1 comment · Fixed by #1961
Assignees
Labels
Bug An issue with our existing, production codebase. workbox-window

Comments

@jeffposnick
Copy link
Contributor

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 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.

@jeffposnick jeffposnick added Bug An issue with our existing, production codebase. workbox-window labels Mar 14, 2019
@philipwalton
Copy link
Member

#1961 should fix this.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An issue with our existing, production codebase. workbox-window
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants