Skip to content

Templates: Fixed the preview changing the built theme files and double query strings on asset links - #145

Closed
whereareiam wants to merge 1 commit into
chore/build-cleanupfrom
fix/preview-dist-stamp
Closed

whereareiam wants to merge 1 commit into
chore/build-cleanupfrom
fix/preview-dist-stamp

Conversation

@whereareiam

Copy link
Copy Markdown
Owner

Summary

The local preview edited the build in dist/forgejo directly to make open pages reload. That caused two problems:

  • Build test failed after a preview session: the preview added ?preview=<revision> to the auto themes' @imports in dist/forgejo/public/assets/css. Until the next bun bundle, src/build-output.test.ts then failed, because it compares those files with dist/<auto>.css.
  • Two question marks in asset links: the stamp went after the path, in front of the content version bun bundle had already added. Links ended up like theme-github-dark.css?preview=<id>?v=<hash>, so the content version became part of the preview parameter.

What changed:

  • ThemeSynchronizer.stage() copies the built css and js into dev/.generated/public/assets. It empties the mounted folders and refills them, rather than replacing them. The reloader stamps that copy and writes preview-revision.json there, so dist stays exactly as bun bundle wrote it.
  • dev/docker-compose.yml mounts dev/.generated/public/assets/{css,js} instead of dist.
  • bun dev:forgejo:sync and the watcher now recreate the Forgejo container instead of restarting it (up -d --force-recreate --no-deps). This way a preview started before this change picks up the new mounts. The data volume stays.
  • The preview revision joins any existing query with &, e.g. ?v=<hash>&preview=<rev>. This applies to auto-theme imports and template links. The browser-side reload script already used URLSearchParams and needed no change.
  • dev/fixtures/README.md explains how to sign in as sam: turn off the automatic sign-in with FORGEJO_PREVIEW_AUTO_LOGIN=false bun dev:forgejo:sync, sign out, then sign in with preview-fixture (FIXTURES.userPassword). README and ARCHITECTURE describe the preview's own copy of the build.

bun dev:forgejo, bun dev:forgejo:sync and bun dev:forgejo:watch run the same steps as before. They now copy the build into dev/.generated before stamping it.

Checks

  • src/preview-reloader.test.ts was rewritten against a dist/forgejo laid out like bun bundle output, including the ?v= versions. The tests check that:
    • dist stays as built;
    • every stamped link has one query;
    • a new revision is published only when ready, and files dropped from the build disappear from the copy;
    • the Compose file mounts only the copy in dev/.generated.
  • bun bundle and all 458 tests pass. I also ran the prepare steps against a real build and found no link with two ?; src/build-output.test.ts still passed afterwards.
  • Not run in Docker: the shared preview was left alone, so the mounts were verified by the test and by reading the Compose file.
  • bun lint does not run in this environment: typescript-eslint does not support the installed TypeScript 7. It fails the same way on dev.

Stacked on #144: review only the last commit; GitHub retargets this pull request to dev once the one below is merged.

Release notes

  • The title follows Area: Description with a listed area
  • The title describes the effect in the past tense, for example Branches: Fixed ...
  • Exactly one label: feature, change, bug, dependencies, or skip-changelog
  • bug only for a bug that shipped in a release; a fix for a bug that only existed on dev is skip-changelog
  • major added when admins must act on upgrade, for example a new minimum Forgejo version
  • Upgrade steps or warnings added to .github/release-notes.md, if admins need them

Checks

  • Tests added or updated
  • Checked in the dev preview at desktop and phone width, in dark and light mode

🤖 Generated with Claude Code

The preview added ?preview=<revision> to the auto themes' imports in
dist/forgejo itself, so src/build-output.test.ts failed after any
dev:forgejo session until the next bun bundle. The stamp also went
after the path, before the content version the bundle had already
appended, which made links with two question marks such as
theme-github-dark.css?preview=<id>?v=<hash>.

ThemeSynchronizer now copies the built css and js into
dev/.generated/public/assets, and the reloader stamps that copy and
writes preview-revision.json there. The Compose file mounts it instead
of dist, and a sync recreates the container rather than restarting it,
so a preview started before this change picks up the new mounts. The
revision joins any existing query with &, keeping one query per link.

The fixture README explains how to sign in as sam, whose password is
preview-fixture like every fixture user other than alex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@whereareiam

Copy link
Copy Markdown
Owner Author

Landing as part of #147, which carries this commit rebased onto dev together with the rest of the stack (merging the stack one by one would need a rebase after every rebase merge). The commit itself is unchanged apart from the rebase.

@whereareiam
whereareiam deleted the fix/preview-dist-stamp branch November 1, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Left out of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant