The Wayback Machine - https://web.archive.org/web/20220527022156/https://github.com/dotnet/aspnetcore/issues/40678
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

[Blazor] Fetch logic should check if the asset is present in the list of included assets before deciding to serve index.html #40678

Open
javiercn opened this issue Mar 12, 2022 · 4 comments
Assignees
Labels
area-blazor blazor-wasm feature-pwa good first issue help wanted
Milestone

Comments

@javiercn
Copy link
Member

@javiercn javiercn commented Mar 12, 2022

async function onFetch(event) {
let cachedResponse = null;
if (event.request.method === 'GET') {
// For all navigation requests, try to serve index.html from cache
// If you need some URLs to be server-rendered, edit the following check to exclude those URLs
//#if(IndividualLocalAuth && Hosted)
const shouldServeIndexHtml = event.request.mode === 'navigate'
&& !event.request.url.includes('/connect/')
&& !event.request.url.includes('/Identity/');
//#else
const shouldServeIndexHtml = event.request.mode === 'navigate';
//#endif
const request = shouldServeIndexHtml ? 'index.html' : event.request;
const cache = await caches.open(cacheName);
cachedResponse = await cache.match(request);
}
return cachedResponse || fetch(event.request);

This causes issues when users try to access a resource on the page directly through the address bar.

The proposal involves updating the service worker to make sure that if a request is for an offline resource, we never serve index.html

Something like

const shouldServeIndexHtml = event.request.mode === 'navigate' && !self.assetManifest.assets.some(asset => asset.url === event.request.url)
@javiercn javiercn added area-blazor blazor-wasm feature-pwa labels Mar 12, 2022
@javiercn javiercn added this to the Backlog milestone Mar 14, 2022
@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Mar 14, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@javiercn javiercn added help wanted good first issue labels Mar 14, 2022
@allprogrammers
Copy link

@allprogrammers allprogrammers commented Mar 28, 2022

Hello Everyone,

I want to work on this issue. Can it be assigned to me ?

@javiercn
Copy link
Member Author

@javiercn javiercn commented Mar 28, 2022

@allprogrammers go for it!

@allprogrammers
Copy link

@allprogrammers allprogrammers commented Mar 29, 2022

Thank you.

I can just copy paste your suggestion but I want to be able to recreate the issue first and see what really the problem is. Can you give some instructions to do that? @javiercn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor blazor-wasm feature-pwa good first issue help wanted
Projects
None yet
Development

No branches or pull requests

2 participants