-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Page refresh loses hashes after service worker update #25889
Comments
This is kind of related to #25778 in a way as they're both dealing with hashes in links. Just in case anyone else has issues using hash links... |
I'm sorry you're running into this issue @ediblecode! Thanks for lettings us know! It would be really helpful if you could provide a minimal reproduction. I'm tagging in @moonmeister who might have more context on |
Thanks for the reply. I did think about a minimal repro but it's pretty
tricky as it requires a build, after you've visited the site so you can
revisit, with a different build hash so the service worker updates, which
is when you'd see the refresh. So not that straightforward I'm afraid
unless there's another way? Although I could set up a minimal repro repo if
that's easier?
…On Tue, 21 Jul 2020, 20:38 Madalyn, ***@***.***> wrote:
I'm sorry you're running into this issue @ediblecode
<https://github.com/ediblecode>! Thanks for lettings us know! It would be
really helpful if you could provide a minimal reproduction. I'm tagging in
@moonmeister <https://github.com/moonmeister> who might have more context
on gatsby-plugin-offline and service workers but it'd be easiest for us
to help debug if we could see a live reproduction of the issue in something
like codesandbox.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#25889 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG2F3DE32CKYWWZ6IBDMILR4XVBPANCNFSM4PCX4QSA>
.
|
Ok, I've create a minimal repro repo, see https://github.com/ediblecode/gatsby-hash-repro.
There must be a build hash used somewhere for the service worker as you need to make a content change to see trigger a service worker update. I hope that helps @madalynrose and @moonmeister but more than happy to add more details/screenshare to demo if needs be. |
There may be other aspects to this that I haven't considered, but I think setting
|
I think you're right @wpj. I initially thought -window.location = pathname
+window.location = to I did wonder if this wouldn't work if there was a prefixed path (sub folder) but looks like the prefixing is done in gatby-link itself: gatsby/packages/gatsby-link/src/index.js Line 196 in 693d4aa
so by the time it get's to |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Definitely not stale |
@ediblecode Don't know if this is still an issue for you but #32323 should address the issue. It also handles query parameters getting dropped which was the bug we had that caused us to look into this. |
Description
I'm linking between pages using a hash to link to a specific section. After a site re-deploy, which I think in turn triggers a service worker update, the page reloads after navigation and loses the hash. Which in turns mean a user isn't taken to the section related to the link they clicked.
From digging around, I think it's caused by this:
gatsby/packages/gatsby/cache-dir/navigation.js
Lines 68 to 73 in 2a72ec1
Where the
___swUpdated
comes from:gatsby/packages/gatsby/cache-dir/register-service-worker.js
Lines 27 to 30 in 2e6825a
I think I might be able to work round it by using
onServiceWorkerUpdateReady
to reload the window myself (keeping the hash), or by settingwindow.___swUpdated = false
like this blog post. But this seems wrong to have to do this, when the default behaviour is to refresh after an update - it feels like navigation.js should reload the page, and keep the hash. Maybe by usingwindow.reload(true)
rather than settingwindow.location
?Steps to reproduce
Expected result
The page reloads, because of a service worker update, with the same URL, including the hash.
Actual result
The page reloads, but excludes the hash and just uses the pathname.
Environment
n/a
The text was updated successfully, but these errors were encountered: