Repository navigation
fix: Load uno-config.js by content version - #1099
MartinZikmund wants to merge 4 commits into
Conversation
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
BrowserEmbedded remains unversioned, offline matching is overly broad, and the required specification is missing.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Fixes stale uno-config.js caching across deployments by adding content-based URL versioning.
Changes:
- Computes and propagates a SHA-256-derived config version.
- Updates browser, service-worker, build, publish, and compression handling.
- Adds tests and deployment caching guidance.
| File | Description |
|---|---|
src/Uno.Wasm.Tests.Fingerprint/test-fingerprint.sh |
Adds end-to-end version validation. |
src/Uno.Wasm.Bootstrap/UpdateUnoConfigVersionTask.cs |
Adds the MSBuild restamping task. |
src/Uno.Wasm.Bootstrap/UnoConfigVersion.cs |
Implements hashing and reference rewriting. |
src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts |
Forwards the version to the config import. |
src/Uno.Wasm.Bootstrap/ShellTask.cs |
Versions generated shell files. |
src/Uno.Wasm.Bootstrap/Embedded/service-worker.js |
Supports offline lookup of versioned config URLs. |
src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets |
Restamps build and publish outputs. |
src/Uno.Wasm.Bootstrap.UnitTests/Given_UnoConfigVersion.cs |
Tests hashing and rewriting. |
doc/deploy-and-publish.md |
Documents cache policies. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
uno-config.js lives in package_<hash>, which hosts cache as immutable (the Uno app template's staticwebapp.config.json does), but the package hash only covers the static files: uno-config.js changes with every build (it names the fingerprinted dotnet.js) while its URL doesn't. A returning visitor then got the previous deployment's config and failed with a 404 on its dotnet.js once that file was gone. index.html now loads uno-bootstrap.js?v=<hash of uno-config.js>, the bootstrapper forwards the version to its uno-config.js import, and the service worker imports it the same way. The version is refreshed whenever the fingerprint update rewrites uno-config.js, after build and after publish. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs
Forward the config version through embedded.js, and only ignore the query string for uno-config.js in the service worker fallback. Add a spec for the config versioning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G7PsEU6gSpLZXrYuK8WWpt
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G7PsEU6gSpLZXrYuK8WWpt
526edf5 to
0d10684
Compare
| foreach (var path in files) | ||
| { | ||
| if (File.Exists(path)) | ||
| { | ||
| File.WriteAllText(path, UnoConfigVersion.Apply(File.ReadAllText(path), version), _utf8Encoding); | ||
| } | ||
| } |
| foreach (var item in ReferencingFiles) | ||
| { | ||
| var path = item.ItemSpec; | ||
| if (!File.Exists(path)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var original = File.ReadAllText(path); | ||
| var updated = UnoConfigVersion.Apply(original, Version); | ||
| if (updated == original) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| File.WriteAllText(path, updated, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); | ||
|
|
||
| // Pre-compressed siblings were produced from the old content and would win content negotiation. | ||
| File.Delete(path + ".gz"); | ||
| File.Delete(path + ".br"); | ||
|
|
||
| Log.LogMessage(MessageImportance.Normal, $"[Uno] Set uno-config.js version {Version} in {path}"); | ||
| } |
| /// </summary> | ||
| private void ApplyConfigVersion() | ||
| { | ||
| var configPath = Path.Combine(_intermediateAssetsPath, "uno-config.js"); |
|
|
||
| var files = new[] | ||
| { | ||
| Path.Combine(_intermediateAssetsPath, "index.html"), |
| var files = new[] | ||
| { | ||
| Path.Combine(_intermediateAssetsPath, "index.html"), | ||
| Path.Combine(_intermediateAssetsPath, "service-worker.js"), |
| { | ||
| Path.Combine(_intermediateAssetsPath, "index.html"), | ||
| Path.Combine(_intermediateAssetsPath, "service-worker.js"), | ||
| Path.Combine(IntermediateOutputPath, "shell-embedded.js"), |
|
Closing in favor of #1077, which fixes the same bug (#1076) by moving On the question of whether the package hash already covers |


Fixes #1090
What changed
uno-config.jslives inpackage_<hash>, which hosts cache as immutable: the Uno app template'sstaticwebapp.config.jsondoes so for/package_*. The package hash only covers the static files, though.uno-config.jschanges with every build, since it names the fingerprinteddotnet.js, while its URL doesn't. A visitor returning after a redeploy got the previous deployment's config, and once itsdotnet.jswas gone, a 404 and.NET runtime initialization failed.index.htmlnow loadsuno-bootstrap.js?v=<first 12 hex of the SHA-256 of uno-config.js>. The bootstrapper reads the version from its own script tag (import.metaisn't available, as the bootstrapper is compiled as a script) and imports./uno-config.js?v=<version>. Every deployment's config gets its own URL.uno-config.jswith the same version. Service worker imports are served from the HTTP cache by default, so it would otherwise precache from a stale config. Its offline fallback matches withignoreSearch, sinceuno-config.jsis precached without the query.ShellTasksets the version when it generates the files. A newUpdateUnoConfigVersionTask_v0refreshes it whenever the fingerprint update rewritesuno-config.js, after build and after publish, and drops the stale.br/.gzof the files it changes.package_*, fingerprinted_frameworkfiles) and what must be revalidated (index.html,service-worker.js, root files), with an Azure Static Web Apps example.Not covered:
index.htmlis rewritten after the SDK generated its endpoints manifest, asuno-config.jsalready was. That only matters to ASP.NET Core hosts usingMapStaticAssets;Uno.Wasm.Bootstrap.Serverserves files from disk.Validation
index.htmlis revalidated → 3× 404 on_framework/dotnet.<v1>.js. Withuno-config.jsservedno-cache(what this change makes unnecessary), the reload loads v2.test-fingerprint.sh: after publishing,index.htmlloadsuno-bootstrap.js?v=andservice-worker.jsimportsuno-config.js?v=, both with the hash of the publisheduno-config.js; the version changes with the next publish. Tests 1–10 pass.uno-bootstrap.js?v=55a40558b363anduno-config.js?v=55a40558b363.Given_UnoConfigVersion.Follow-up for unoplatform/uno.templates: the
/package_*immutable rule becomes correct with this change;index.htmlshould beno-cacherather thanmax-age=3600.🤖 Generated with Claude Code
https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs