Currently if I use PWA as logged-in user the Service Worker caches all admin links and contextual links. After I log out and turn of network, the offline page is shown. All cached links are rendered. I have to reset the service worker, to hide them again.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | pwa_user_cache_reset-3078282-8.patch | 2.58 KB | daniel kulbe |
Issue fork pwa-3078282
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
alexborsody commentedI notice this too as it caches the html that's rendered to an admin on D8. But it only effects admin users who have access to admin toolbar and usually resets on a page refresh when back online.
Comment #3
ruplAre we walking about public pages that have admin-enabled portions? Short-term workaround: consider removing the
access_pwapermission for admins. As it is designed at the moment, the PWA is only intended for and tested against anonymous visitors. Caching for authenticated users is another challenge.If you have any thoughts regarding how we can intelligently cache this for a logged-in user we'd be open to discuss how that can be solved. Over the years we have discussed it a few times and it's unfortunately not obvious to me how we solve it.
The
fetchevent listener does not have to work solely on the basis of URL path. Perhaps if Drupal core outputs another reliable signal on every request to a logged-in user we could partition the cache based on that aspect of the HTTP responses.Comment #4
ruplThis would be the conditional to alter. We're doing a very simple check for
response.okbut it could be anything.https://git.drupalcode.org/project/pwa/blob/b343f48e2404bfc1169879c91a7b...
I took a look around the one D8 site I had at my disposal and noticed that on pages with the toolbar, I get a
Cache-ControlHeader that seems like it could be useful:At first glance, it seems like a reliable signal we could make use of. As long as it comes from core, I'd be open to integrating it into the SW network strategy functions.
Comment #5
alexborsody commentedThanks for the suggestion rupl, I need to take a look at the D7 version again and see how it's handling the `access_pwa` permission to the SW, your solution should solve this issue of caching anonymous pages for admin the role.
To your other point, maybe the caching for authenticated users could be done like, #3060726: Add support for a second service worker.
This is not really the same as the above issue posted. But it addresses the broader question of caching for authenticated users, a common use-case.
Comment #6
alexborsody commentedComment #7
nod_took care of it in the 7.x-2.x branch by sending a clear-site-data header on user logout.
Comment #8
daniel kulbeCould work like this in 8.x-1.x branch ...
Comment #9
nod_Less elegant in D8 :p
Comment #10
daniel kulbeBut object oriented. :P
Comment #11
tyler36 commentedUnable to reproduce problem:
- Install and enable
PWA 1.4- Config PWA: Urls to cache: "/"
- View homepage as
User 1- Logout via NAV link
- Turn off network in
Chrome 88 DevTools- See standard homepage with "Login link"
- Refresh page and see same
- Clicking "Login" displays offline page
- Attempt to "search" displays offline page
Am I missing something?
Comment #12
tyler36 commentedOK ... can reproduce. I needed to create a new node first.
- Install and enable PWA 1.4
- Config PWA: Urls to cache: "/"
- Create article content: 'node/1'
- View page: 'node/1'
- Logout out
- Turn off network
- Visit: 'node/1'
- 🐛 Displays "admin" version of page with admin_toolbar and edit/delete/revision tabs.
Comment #13
tyler36 commentedPatch #8 fails. Need to remove "PWAController" reference.
Comment #14
ambient.impactOne addition I'd recommend to the patch in #8 is to implement
hook_user_logout()to ensure other methods of logging out a user also cause the header to be sent, e.g. an admin action or via Drush. Of course, this now means that you can't guarantee that the current user is the one being logged out, so you'd have to queue this somehow to be sent the next time the logged out user's Service Worker is online and send it then.Comment #17
ambient.impact@AlexBorsody Um, looks like the actual patch file got committed in that last merge request. Very meta, but I suspect it wasn't intentional, so opening another merge request to delete it.
Comment #19
alexborsody commentedComment #22
anybody@AlexBorsody, @nod_ and @Daniel Kulbe sadly seems this caused a regression: #3279305: Log in / log out problems in Chrome
Could you perhaps have a short look at #3279305: Log in / log out problems in Chrome if you have an idea?
Sending the https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data causes login / logout issues in Chrome.