Skip to content

fix: Load uno-config.js by content version - #1099

Closed
MartinZikmund wants to merge 4 commits into
dev/mazi/dotnetjs-stale-fingerprintfrom
dev/mazi/uno-config-cache-safe
Closed

MartinZikmund wants to merge 4 commits into
dev/mazi/dotnetjs-stale-fingerprintfrom
dev/mazi/uno-config-cache-safe

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

Fixes #1090

Stacked on #1098 (the post-publish steps it changes). Retarget to main once it's merged; CI only runs for PRs into main.

What changed

uno-config.js lives in package_<hash>, which hosts cache as immutable: the Uno app template's staticwebapp.config.json does so for /package_*. The package hash only covers the static files, though. uno-config.js changes with every build, since it names the fingerprinted dotnet.js, while its URL doesn't. A visitor returning after a redeploy got the previous deployment's config, and once its dotnet.js was gone, a 404 and .NET runtime initialization failed.

  • index.html now loads uno-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.meta isn'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.
  • The PWA service worker imports uno-config.js with 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 with ignoreSearch, since uno-config.js is precached without the query.
  • ShellTask sets the version when it generates the files. A new UpdateUnoConfigVersionTask_v0 refreshes it whenever the fingerprint update rewrites uno-config.js, after build and after publish, and drops the stale .br/.gz of the files it changes.
  • Docs: a caching section in the publishing page lists what can be immutable (package_*, fingerprinted _framework files) and what must be revalidated (index.html, service-worker.js, root files), with an Azure Static Web Apps example.

Not covered: index.html is rewritten after the SDK generated its endpoints manifest, as uno-config.js already was. That only matters to ASP.NET Core hosts using MapStaticAssets; Uno.Wasm.Bootstrap.Server serves files from disk.

Validation

  • Reproduced on the Uno 7.0 app template (bootstrap 10.0.96) with the template's SWA cache rules in a test server: first visit on v1, deploy v2, reload once index.html is revalidated → 3× 404 on _framework/dotnet.<v1>.js. With uno-config.js served no-cache (what this change makes unnecessary), the reload loads v2.
  • New Test 10 in test-fingerprint.sh: after publishing, index.html loads uno-bootstrap.js?v= and service-worker.js imports uno-config.js?v=, both with the hash of the published uno-config.js; the version changes with the next publish. Tests 1–10 pass.
  • Browser: the RayTracer sample published with this change boots, requesting uno-bootstrap.js?v=55a40558b363 and uno-config.js?v=55a40558b363.
  • Unit tests: Given_UnoConfigVersion.

Follow-up for unoplatform/uno.templates: the /package_* immutable rule becomes correct with this change; index.html should be no-cache rather than max-age=3600.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs

Copilot AI balanced review requested due to automatic review settings October 1, 2026 11:42
@MartinZikmund MartinZikmund self-assigned this Oct 1, 2026
@mergify

mergify Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

BrowserEmbedded remains unversioned, offline matching is overly broad, and the required specification is missing.

Review effort: Balanced
Findings: 2 Medium severity · 1 Low severity

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.

@MartinZikmund
MartinZikmund added this pull request to stack #1106 October 7, 2026 15:49
MartinZikmund and others added 4 commits October 7, 2026 17:49
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
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
Copilot AI balanced review requested due to automatic review settings October 7, 2026 15:49
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/uno-config-cache-safe branch from 526edf5 to 0d10684 Compare October 7, 2026 15:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment on lines +693 to +699
foreach (var path in files)
{
if (File.Exists(path))
{
File.WriteAllText(path, UnoConfigVersion.Apply(File.ReadAllText(path), version), _utf8Encoding);
}
}
Comment on lines +48 to +70
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"),
@MartinZikmund

Copy link
Copy Markdown
Member Author

Closing in favor of #1077, which fixes the same bug (#1076) by moving uno-config.js out of package_<hash> to the root. It's simpler and was first. The useful docs from this PR (the Azure Static Web Apps cache example and the warning about missing Cache-Control on root files) are now on #1077.

On the question of whether the package hash already covers uno-config.js: it doesn't. ShellTask.GeneratePackageFolder() hashes StaticWebContent before GenerateConfig() writes the file, and the fingerprinted dotnet.<fp>.js name is only patched in afterwards by _UnoUpdateDotnetJsFingerprint / _UnoUpdateDotnetJsFingerprintPublishOutput, in place inside the already-named folder. So a managed-code-only change gives a new uno-config.js under the same package_<hash>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Returning visitors load a stale uno-config.js after a redeploy and fail with a 404

3 participants