-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Originally reported as #19775, but the issue is slightly more general than that so I'll rephrase it.
Problem: If you use Git [1] as a way of transferring build output to your production server, and the production server has different newline conventions from the build server [2], then content hashes in text files (such as blazor.webassembly.*.js
) will not match and the application will not load.
[1] i.e., the source control technology, not necessarily GitHub. So this applies to Kudu too.
[2] e.g., build machine is Windows and production server is Linux, or vice-versa
This happens because by default Git performs automatic CRLF conversions on commit.
Strictly speaking this issue is not specific to Blazor, but would apply to any web technology that computes subresource integrity hashes during build. However it's a bigger issue for Blazor because (1) we're now computing subresource integrity hashes during build by default, and (2) an unusually large proportion of Blazor developers use Windows.
Possible solutions
People have two main ways to avoid this problem. They can use <BlazorCacheBootResources>false</BlazorCacheBootResources>
to disable the caching-and-integrity-checking feature entirely, or they can put a .gitattributes
file in their repo specifying autocrlf=false
.
The question is: how are we going to help people with this?
1. Docs only
We could add documentation to the deployment pages giving advice about git-based deployment mechanisms, especially highlighting that this affects GitHub Pages.
We would advise people to add a .gitattributes
file to their repo specifying autocrlf=false
(at least in the subdirectory representing their GitHub Pages content, i.e., the published output).
2. Auto-generate a .gitattributes
file
On publish, we could place the relevant .gitattributes
file in the output.
It sucks pretty bad for us to couple aspects of our build pipeline to a particular source control system, even if it is the de-facto industry standard. We don't know whether the customer is planning to use Git as a deployment mechanism, so we don't know whether the .gitattributes
file is really relevant.
We could:
- [A] Just do it all the time regardless, reasoning that it's not harmful in the cases where it's not needed. Possibly with an MSBuild option to disable this for people who care.
- Pro: just works
- Con: clumsy
- [B] Or, do that but with the default being "off", so people have to explicitly enable it by setting
<DisableGitAutoCRLFInPublishOutput>true</DisableGitAutoCRLFInPublishOutput>
- Pro: convenient for people who know about it
- Con: undiscoverable without reading docs. People will still have deployment problems by default and not know what to do. If we're relying on people reading docs, why not just have docs telling them to add a
.gitattributes
file manually?
- [C] Or, have the default on/off setting determined by the condition "is the publish output going into a git repo?". We can detect this by scanning upwards for the presence of a
.git
directory.- Pro: just works at least in the most obvious and basic cases, without cluttering things in non-Git scenarios.
- Con: Since Git is so overwhelmingly prevalent, why go to all this effort to detect non-Git scenarios? Virtually nobody is not using Git.
- Con: Still doesn't work in more complicated cases, such as when the build process is operating on files outside a Git repo (due to some custom CI setup) but the results are then being copied into a Git repo.
My first instinct is to think about a docs-only solution initially, and consider upgrading it to a more automated solution if we keep getting customer reports about it.