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.

Issue fork pwa-3078282

Command icon 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

Eric Heydrich created an issue. See original summary.

alexborsody’s picture

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

rupl’s picture

Are we walking about public pages that have admin-enabled portions? Short-term workaround: consider removing the access_pwa permission 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 fetch event 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.

rupl’s picture

This would be the conditional to alter. We're doing a very simple check for response.ok but 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-Control Header that seems like it could be useful:

# anonymous traffic
Cache-Control: max-age=900, public

# user/1 looks at same page
Cache-Control: no-cache, no-store, must-revalidate

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.

alexborsody’s picture

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

alexborsody’s picture

Title: Service Worker caches toolbar and contextual links » Service Worker caches admin toolbar and contextual links
Priority: Normal » Minor
nod_’s picture

Priority: Minor » Normal

took care of it in the 7.x-2.x branch by sending a clear-site-data header on user logout.

daniel kulbe’s picture

Status: Active » Needs review
StatusFileSize
new2.58 KB

Could work like this in 8.x-1.x branch ...

nod_’s picture

Less elegant in D8 :p

daniel kulbe’s picture

But object oriented. :P

tyler36’s picture

Unable 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?

tyler36’s picture

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

tyler36’s picture

Patch #8 fails. Need to remove "PWAController" reference.

Checking patch pwa.module...
error: while searching for:
 * PWA hooks.
 */
use Drupal\Core\Url;
use Drupal\pwa\Controller\PWAController;


error: patch failed: pwa.module:5
error: pwa.module: patch does not apply
ambient.impact’s picture

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

ambient.impact’s picture

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

alexborsody’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

anybody’s picture

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