php-wasm icon indicating copy to clipboard operation
php-wasm copied to clipboard

handleFetchEvent should not perform a fetch

Open mglaman opened this issue 1 year ago • 1 comments

Per https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent, event listeners for FetchEvent should return responses using respondWith or do nothing. The code uses respondWith for the PHP response, but then there is an else and a fetch performed. This is doubling the request.

Need to remove

		else
		{
			return fetch(event.request);
		}

mglaman avatar Sep 27 '24 13:09 mglaman

Looks like this problem was attempted to workaround here:

			isWhitelisted = url.pathname.substr(0, prefix.length) === prefix && url.hostname === self.location.hostname;

			isBlacklisted = url.pathname.match(/\.wasm$/i)
			|| staticUrls.includes(url.pathname)
			|| (this.exclude.findIndex(exclude => url.pathname.substr(0, exclude.length) === exclude) > -1)
			|| false;

mglaman avatar Sep 27 '24 13:09 mglaman

@mglaman

That's something Patricio and I have been going over. We need away to get through the service worker and put a request all the way through to the actual server in some cases.

Are you suggesting we remove the fetch call alltogether, or use respondWith instead of return?

seanmorris avatar Oct 06 '24 16:10 seanmorris

Remove the fetch or use respondWith. I'd opt for full removal and allow normal browser behavior

mglaman avatar Oct 06 '24 16:10 mglaman