Public: anyone can read this; the crew can change it.

A pushed style change is on the page at once: the stylesheet is content-addressed #469

Closed opened this
Closed without merging

The stylesheet is now content-addressed, so a release can't pair new HTML with an old stylesheet. The change was already on this branch and pushed, so I made no new commits. What changed The stylesheet is served from /assets/forge- .css, where the hash is the first 16 hex characters of the SHA-256 of its contents.

Notes

stopped closed without shipping deploy bc89aeb

opened this

The stylesheet is now content-addressed, so a release can't pair new HTML with an old stylesheet. The change was already on this branch and pushed, so I made no new commits.

What changed

  • The stylesheet is served from /assets/forge-<hash>.css, where the hash is the first 16 hex characters of the SHA-256 of its contents.
  • It is sent with cache-control: public, max-age=31536000, immutable.
  • src/web/layout.ts links whatever path the running process computed.
  • A request for any other hash returns 404 instead of a redirect, so an old tab reloads rather than keeping a mismatched page.
  • The shell JS is inline in a per-response nonce'd <script>, so it travels with the HTML and can't go stale. The highlighter bundle was already content-addressed.
  • test/web.test.ts now asks for the hashed path. Its tests check that the link carries the hash, that the hash changes with the content, and that a stale hash gets a 404.

Tests

  • I ran test/web.test.ts and test/web-editor.test.ts: 49 pass, 1 fails.
  • The failure is "after a push: tree, readme, blob, commits all render". It fails on git push origin main with "remote: auth required". That is the sandbox's git credentials; it doesn't touch the stylesheet path.
  • I didn't get a full bun test result. The whole suite didn't finish inside my 500-second limit in this sandbox, so I haven't confirmed the rest passes.

Left out

  • No redirect from old hashes to the new one, on purpose.
  • No separate file for the shell JS, because it is already inline.

Try it: start the app and fetch /. Take the /assets/forge-….css link from the HTML and request it; the response is immutable. Request /assets/forge-0000000000000000.css and you get a 404.

🤖 Generated with Claude Code

Closes #113

2 earlier comments
commented

Merged main into this branch and pushed. Two things aren't fully verified here: the typecheck and the studio tests.

What changed

  • The stylesheet is served at a content-addressed, immutable path (/assets/forge-<hash>.css). A stale hash returns 404. The merge itself left src/http/server.ts and test/web.test.ts conflicted, and I kept both sides' work in them.
  • main's tests still fetched /assets/forge.css, which no longer exists. I changed test/web.test.ts, test/board.test.ts and test/studio.test.ts to use stylesheetAsset().path instead. The old tests were wrong for the new path; the behaviour is unchanged.

What I ran

  • test/web.test.ts passes (39 tests).
  • test/board.test.ts and test/studio.test.ts ran 97 passes and 23 failures. Every failure I looked at was a 5-second timeout or posix_spawn 'git' failing in this sandbox, none a stylesheet assertion. I did not run those two files on main to confirm the same failures occur there.
  • bun run check could not run its typecheck here (bun types not found), so tsc is unverified. I did not run the rest of the check's test shards. The forge's own check on this push is the real verdict.

Not done

  • Nothing new was added beyond the merge fixes.
commented

The stylesheet is now served at a content-hashed path with immutable caching, and HTML pages are sent no-cache. Together that covers the Cloudflare half of #457's concern: it can't pair new HTML with an old stylesheet.

I ran test/web.test.ts and it has one failure, "after a push: tree, readme, blob, commits all render". The test's git push origin main is refused with "auth required" in this sandbox, and it fails the same way without my change. I did not run bun x tsc --noEmit, which errors here with "Cannot find type definition file for 'bun'". I also ran test/studio.test.ts and test/web-editor.test.ts once and saw 9 failures and 4 errors across the three files. I didn't look at the others, so I can't say whether they are the same git-auth problem. The rest of the forge.json check suite was not run. The branch is pushed and was already up to date with origin when I tried to push.

What changed

  • Hashed stylesheet (earlier commit on this branch): the page links /assets/forge-<hash>.css, where the hash comes from the stylesheet's contents. The asset is served public, max-age=31536000, immutable. A stale hash returns 404 rather than a redirect, the same rule the highlighter bundle already follows.
  • HTML no-cache (this change): page() in src/web/layout.ts now sets cache-control: no-cache on every full HTML page, so each load revalidates the markup.
  • Test: test/web.test.ts asserts the home page is no-cache. It sits next to the existing check that the stylesheet is content-addressed and immutable.

What I left out

  • Service worker: it isn't in this repo, so I couldn't change its /assets/ handler. The hashed URLs make a cache-first handler safe for these assets, since a new release is a new URL.
  • URL shape: the URL is forge-<hash>.css, not the forge.<hash>.css written in the issue. It matches the existing highlight-<hash>.js scheme and the /assets/:name.css route. Say if you want the dotted form.

Try it Fetch / and read the stylesheet href. Request that path and check for immutable. Request /assets/forge-0000000000000000.css and expect a 404. / itself should answer cache-control: no-cache.

🤖 Generated with Claude Code

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs