-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 |
@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 |
@maraf In the binlog files under wwwroot/_framework you will find all files in the build output starting with dotnet.js. |
@steamonimo Thank you! The problem seems to be the one described in #102272 (comment) - brotli compressed file is stale. We are tracking that one. It can be workarounded by cleaning the publish dir before doing the next one, as publish is not incremental at the moment (as you can see on your disk) |
@maraf I used a new publication folder. After rebuild there are less dotnet.js related files (see binlog files but the problem remains the same. For git the remaining files are the same files as the previous commit (unchanged). Detail: the error in the browser log is now about the digest which is new (see readme): Failed to find a valid digest in the 'integrity' attribute for resource 'http://127.0.0.1/_framework/dotnet.native.wasm' with computed SHA-256 integrity 'U1JSgnum2OTerSq8i5Y9L17deHEWJmae0djinSPLyJM='. The resource has been blocked. However, the status code for dotnet.native.wasm is 200 (OK). The problem must be digest related... Added: blazor.boot.json for digest analysis in binlog/wwwroot/_framework |
The tool integrity.ps1 does also indicate that dotnet is the root of the problem. All files mentioned below and the blazor.root.json with the digest info can be found in my binlog. Invoke-WebRequest: integrity.ps1:112 |
The problem persists with Visual Studio 17.10.2. The binlog has been updated... |
@maraf The problem also persists with Visual Studio 17.10.3. The binlog has been updated. The error in the browser changed to: Failed to find a valid digest in the 'integrity' attribute for resource 'http://127.0.0.1/_framework/dotnet.native.wasm' with computed SHA-256 integrity 'U1JSgnum2OTerSq8i5Y9L17deHEWJmae0djinSPLyJM='. The resource has been blocked. |
@steamonimo |
Done everything but was unable to make it work, deleted the bin and obj twice before rebuilding and publishing & cleared the Please if there is any workaround mention. I am using blazor WebApp and my app keep running on server & unable to start WASM due to this website hangs because to slow internet. |
Any update? I'm using Git Actions to Build and Deploy no bin/obj Folders to delete. |
@LeeStevens318 Could you please collect a binlog from your CI build/publish and share it either here or through https://developercommunity.visualstudio.com/? Does your runner cache in anyway build outputs between runs? The only issue we have been able to find so far is related to incremental publish. |
Had the same issue, no bin/obj to delete. Our CI was targeting the latest SDK. Fixed it by targeting 8.0.204 (for now). |
@nicholasfortier Could you please collect a binlog from your CI build/publish and share it either here or through https://developercommunity.visualstudio.com/? Does your runner cache in anyway build outputs between runs? |
The issue persists when publishing to a folder from Visual Studio v17.11.2 ( |
Clearing the |
@omni-htg Did you updated SDK after last publish? Can you please collect binlog from publish and share it here or though https://developercommunity.visualstudio.com ? |
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: