Closed nicolasHul closed 2 years ago
@nicolasHul
and setting the
EnvironmentsForWork
to "Production" AND "Development",
I guess setting the EnvironmentsForWork
parameter to include "Development" is the reason why there was no effect when you clicked the "Update now" button.
When you run the Blazor Wasm project on Visual Studio or .NET CLI, such as dotnet watch
or dotnet run
, the loading service worker script is ./wwwroot/service-worker.js
, not ./wwwroot/service-worker.published.js
.
Therefore, you also have to change your ./wwwroot/service-worker.js
,
from:
self.addEventListener('fetch', () => { });
to:
self.addEventListener('fetch', () => { });
// π add this line.
self.addEventListener('message', event => { if (event.data?.type === 'SKIP_WAITING') self.skipWaiting() });
After doing the above, the "Update Now" button should work expectedly, I think.
@nicolasHul
it was completely un-styled.
You also have to include the "isolated style" file of Blazor apps in your index.html
.
The path of the "isolated style" file is {Assembly Name}.styles.css
. For example, if the assembly name of your Blazor application is MyBlazorApp1
, you should make the index.html
of that app to be like the below:
<html>
<head>
...
<!-- π Add this "link" element. -->
<link href="MyBlazorApp1.styles.css" rel="stylesheet">
...
Please see also the Microsoft Docs site the following link: https://docs.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-6.0#css-isolation-bundling
If you don't prefer to use the Blazor CSS isolation feature, include the _content/Toolbelt.Blazor.PWA.Updater/Toolbelt.Blazor.PWA.Updater.bundle.scp.css
file instead of {Assembly Name}.styles.css
.
@nicolasHul
it was completely un-styled.
You also have to include the "isolated style" file of Blazor apps in your
index.html
.The path of the "isolated style" file is
{Assembly Name}.styles.css
. For example, if the assembly name of your Blazor application isMyBlazorApp1
, you should make theindex.html
of that app to be like the below:<html> <head> ... <!-- π Add this "link" element. --> <link href="MyBlazorApp1.styles.css" rel="stylesheet"> ...
Please see also the Microsoft Docs site the following link: https://docs.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-6.0#css-isolation-bundling
If you don't prefer to use the Blazor CSS isolation feature, include the
_content/Toolbelt.Blazor.PWA.Updater/Toolbelt.Blazor.PWA.Updater.bundle.scp.css
file instead of{Assembly Name}.styles.css
.
This seemed to do the trick. The extra self.addEventListener('message', event => { if (event.data?.type === 'SKIP_WAITING') self.skipWaiting() });
for the development did not work, but after adding the <link href="MyBlazorApp1.styles.css" rel="stylesheet">
it did work.. Thank you!
@nicolasHul
Thank you for reply!
The extra self.addEventListener('message', event => { if (event.data?.type === 'SKIP_WAITING') self.skipWaiting() }); for the development did not work
Yeah, I guess that change also remained in the "waiting to activate" status at first. Therefore it looked like that change had no effect. But in fact, the changed script was loaded correctly but just waiting for shutting down all browser instances once, I guess.
Please see also my latest article below:
Anyway, I'm happy for you because this problem has gone away. π
So after adding the
PWAUpdater
to my MainLayout.razor, and setting theEnvironmentsForWork
to Production AND Development, I am getting the 'new version available', though when I click the 'UPDATE' button, nothing happens. I also don't get any error messages whatsoever. It looks like it cant find it's JavaScript files / parts, though, when looking at the folder structure it references it correctly.What also seemed a bit odd was that when it first loaded, it was completely un-styled. None of the default values were added, also setting the variables in the style.css file didn't do anything. Though I thought this could be some other CSS library interfering (MudBlazor or something else), so I just changed the styles by directly targeting the CSS classes.
I am running a PWA, Blazor WebAssembly CORE hosted application. Do I need to add the packages in the server project as well to get it to work..?
My service-worker.published.js is looking as follows:
and my index.html: