-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
dotnet.js
cache busting (fingerprinting), Symptom: Cannot read properties of undefined (reading 'out')
#102272
Comments
Related: Failing lines of code:
|
cc @pavelsavara |
perhaps we could somehow attach build timestamp in the blazor code something like The other option is to bundle dotnet.js inside blazor's JS file. Assuming that it doesn't have the same issue. |
There is a guidance about hosting and upgrading blazor apps dotnet/aspnetcore#52022 (the title mentions "major" upgrade, but in reality the situation can happen even with servicing release). The situation will be better for hosted mode in .NET 9 thanks to dotnet/sdk#39405 and dotnet/sdk#39636. For standalone mode ideally we should be fingerprinting everything (blazor.js, dotnet.js, all dlls/wasms, but also scripts and styles from nuget packages). But that requires rewriting code that references those files. Unlike for webpack and similar we don't have tooling to do it safely. We should review again if we can it do for the most typical scenarios
This is unfortunately just about moving the problem to a different file |
Is there any way we can manually introduce any extra cache-busting? Ctrl+F5 is an obvious solution, but many of our customers are non-technical and they'll end up having to raise a support ticket with us to find that out. For unrelated reasons we have to adopt patch releases of dotnet very quickly, and I'd rather avoid causing our customers grief a bunch more times before .NET 9 releases. |
dotnet/aspnetcore#55751 (comment) "Custom middleware that sets |
Which isn't strictly cache-busting of course... :-) It's cache-punting. |
My solution for this Chrome 'feature' in the past was for each deployment to go into a different versioned folder, i.e. Of course this isn't exactly trivial to do, but it eliminates the need to find a way to append |
We can use <script src="_framework/blazor.web.js?v=8.0.5" autostart="false"></script>
<script>
Blazor.start({
webAssembly: {
loadBootResource: function (type, name, defaultUri, integrity) {
switch (type) {
case 'dotnetjs':
return `_framework/${name}?v=8.0.5`;
}
}
}
});
</script> In the sample I'm adding also a query string for blazor.web.js, which shouldn't be required for this particular issue. Standalone app can be modified similarly. More details in https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/startup?view=aspnetcore-8.0#load-client-side-boot-resources |
@maraf is there a chance that blazor/dotnet.js get out of "sync"? if not, we could on the Blazor side, stamp the version for the import as part of the build process, and we could then also stamp the 8.0.x on the relevant dotnet.js file as part of the build to make sure everything lines up. |
Ideally no, but blazor.js comes from a package with expicit version in csproj. Dotnet.js version might be affected by presence of workload and currentness of workload manifest. In SDK previews targeting downlevel is also not very stable. The only 100% safe solution from my POV is to put a placeholder in blazor.js and replace it with actual version (fingerprint) of dotnet.js during app build. |
We need to make sure that the whole chain starting with HTML has ability to bust the cache. It could be hash in the file name or it could be query string. Trying to solve this problem in the middle of the dependency chain (dotnet.js) would not work. Adding Etag to HTML file could make the validation cheap. |
Yes, using |
For me the two weak points of Blazor WebAssembly have always been cache-busting and the need to set the From my
|
This synthesized CSS file is sent with an |
AFAIK the problem is that it does set |
Ok, that would explain it. Re. index.html / App.Razor, I've never had a problem with the browser caching the Blazor WebAssembly-served HTML. E.g. all changes I make here are immediately picked up, and I've never had to worry about having to hit ctrl+F5 or anything like that. |
From my testing it has always served HTML with |
Hey. Also getting the issue here. Have tried the above workaround regarding the <script src="_framework/blazor.webassembly.js?v=8.0.5" autostart="false"></script>
<script>
Blazor.start({
loadBootResource: function (type, name, defaultUri, integrity) {
console.log(`Loading: '${type}', '${name}', '${defaultUri}', '${integrity}'`);
switch (type) {
case 'dotnetjs':
return `_framework/${name}?v=8.0.5`;
}
}
});
</script> We are deploying using Azure DevOps, and calling the task |
@pingu2k4 Can you please verify that the deployed app contains correct |
Hey. :) To be clear, our app still works locally, but we have not updated our local .net to 8.0.5 yet. We are building on Azure devops, and deploying to azure static web app. The build pipeline appears to be successful, but loading the site, we get the same errors as posted in this issue. All the static assets appear to be correct etc, but the blazor site gets stuck on the initial loading screen, with the errors matching those in this issue. The cache busting mechanism is also working, as in the files being downloaded have the appended query. Originally posted an issue before we found this issue here: Azure/static-web-apps#1475 |
I am having the exact same problem. Also deploying to Azure Static Web Apps. Runs fine locally. I also tried the above cache busting work around, but didn't fix my problem either. |
@pingu2k4 @double-dubs could you check that the file in your wwwroot folder (do a local publish) is the same as the one you can get from an in-private browser window navigating to your deployed site? (size and hash) To compare the hashes, from powershell you can run |
One thing I am noticing, is when I do a local publish and look in the _framework folder the dotnet.js file is dated 4/16/24 and 36KB. Is that correct? Would that be the latest build date? Many of the other files have newer or today's date on them. |
@double-dubs that file is not modified by the build, it's just copied, so it makes sense for it to have an older timestamp. That said, hashes are the way to know for sure what's going on. |
Ok, the hash did NOT match on the dotnet.js file. I did a hash on the blazor.webassebly.js file and that one matched. Is Azure static web apps doing some caching on that file? I looked in the portal UI and don't see any options to clear the cache. |
Hey, The files when locally published to folder, versus published to SWA through our azure pipeline differs. I made a diff in case that is useful... |
Based on the git hashes in the provided diff, your local dotnet.js is |
Running A small example, but on the left in this screenshot was the azure devops pipeline logs from the last successful build, and on the right is deploying the same commit once it started failing. |
The |
Brotli compressed Setup
Repro
Output in bin\Release\net8.0\publish\
msbuild.binlog.zip (the asset is
For build compression, the file hash is computed from runtime pack location, and so it changes when runtime pack version changes (because of different location). For publish compression, the file hash is computed from build output path (eg. This logic seems to be correct only when "runtime pack file" is newer than "last build compressed file" (the same for GZip) https://github.com/dotnet/sdk/blob/main/src/StaticWebAssetsSdk/Tasks/Compression/BrotliCompress.cs#L93 It can probably happen for any asset coming directly from runtime pack and not modified during publish. Assemblies are now transformed to webcil, ICU and all JS files might be probably affected. |
I've just fired up my Blazor App in VS2022 preview, I think for the first time since upgrading to 17.11 preview 1.0, and have got this which I think might be related? (question mark because I'm not sure I understand the issue). This is just running it up in debug. I tried deleting the bin & obj folders, but that made no difference.
|
Same problem but with a twist: It runs in development but deployed to the same machine it does not run. It makes no difference if the cache is cleared or not: http://localhost/_framework/dotnet.runtime.8.0.5.8hv7wyhg5a.js:3:198913 I find it interesting that after the installation of the visual studio update (17.10.1) AND hosting-package for 8.0.6 the command dotnet --version does not give me 8.0.6 but 8.0.300. What a bummer. My blazor based release pipeline came to a total standstill and client is not amused. Uninstalling visual studio update 17.10.1 now. Same problem with 17.10.0 and - another bummer - you can not go back to 17.9.x ! |
@steamonimo What do you mean by deployed? Are you doing it from VS or command line? Can you produce a binlog and share it (how to here https://msbuildlog.com)? |
@maraf Here are the binlog files. Please let me know if you need more! |
@steamonimo Sorry for late reply. From the build log is visible that it skipped copying |
Is there an existing issue for this?
Describe the bug
When upgrading from 8.0.4 to 8.0.5, the
dotnet.js
changed.In opposite to
dotnet.native.{fingerprint}.js
anddotnet.runtime.{fingerprint}.js
, thedotnet.js
is not fingerprinted and thus cached. The usual Clear site data in F12-DevTools do not help as the file is cached by the browser and still taken from "(disk cache)".The 8.0.4
dotnet.js
is not compatible with 8.0.5dotnet.native.{...}.js
ordotnet.runtime.{...}.js
and the symptom is:(No
module
parameter set when callingconfigureRuntimeStartup()
frominitializeModules()
.)Expected Behavior
dotnet.js
to be correctly fingerprinted (As it already used to be before splitting to several files?).Steps To Reproduce
VS 2022 17.9.6 - Create new BWA - WebAssembly project + run locally in browser.
Update VS to 17.9.7 (brings dotnet 8.0.5).
Run the same project again.
Exceptions (if any)
No response
.NET Version
8.0.5 (9.0.0-preview3 still does not resolve this issue)
Anything else?
WORKAROUND: Ctrl+F5 in browser to force reloading the file.
(It seems this is already in progress, as there are some options in tests which enable checking the fingerprinting on
dotnet.js
.)The text was updated successfully, but these errors were encountered: