Skip to content

🍕 vite: write dev templates to the same 6 files as production - #289

Merged
jjpaulino merged 2 commits into
masterfrom
jordan/template-js-loading-kiln-a06d0b
Nov 16, 2026
Merged

jjpaulino merged 2 commits into
masterfrom
jordan/template-js-loading-kiln-a06d0b

Conversation

@jjpaulino

Copy link
Copy Markdown
Member

What does this PR do?

Dev builds of clay vite now write Handlebars templates to the same six public/js/_templates-{a-d,…,u-z}.js files as minified builds, just not minified, instead of one <name>.template.js per template. Each build also removes leftover *.template.js files. In watch mode, a template that fails to compile keeps its last good version in its file.

No issue: a sites developer asked why Kiln edit mode downloads every .template.js file.

Why are we doing this? Any context or related work?

Kiln edit mode needs every template: it re-renders components in the browser and can add components that aren't on the page. So a dev build of sites put 638 template <script> tags on every edit page. In Chrome, those 638 files took 104–110 ms to run, against 23–26 ms for the same code in six files. sites globs both layouts, so a checkout holding both loaded every template twice.

Where should a reviewer start?

writeOutput in lib/cmd/vite/templates.js. Minified output is unchanged.

Manual testing steps?
  • jest and eslint pass (31 suites, 675 tests). Removing the leftover cleanup or the last-good fallback each makes a new test fail.
  • Built sites' templates with this branch. Each dev file is byte-identical to the old per-template files joined together (638 templates, same values when evaluated). The minified files are byte-identical to master's. The dev template build takes 0.6–0.7 s.
  • Loaded the six dev files in Chrome: all 638 templates register.
Screenshots

None.

Additional Context

  • sites reads its list of template files once, when the server starts. Restart the app once after the first build with this version.
  • clay compile (Browserify) still writes one file per template in dev, and sites' local default is still Browserify. Devs see this change only on the Vite pipeline.
  • Needs an rc release and a sites bump.

Kiln edit mode loads every template. Dev builds wrote one
<name>.template.js per template (638 requests on sites); minified
builds write six _templates-*.js files. Dev builds now write those
six files too, unminified, and remove leftover *.template.js files,
so a site that globs both layouts no longer loads every template
twice. A template that fails to compile during watch keeps its last
good version instead of dropping out of its file.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T20:06:04.242507Z b8569be New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coveralls

coveralls commented Nov 11, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 85.71% (-0.008%) from 85.718% — jordan/template-js-loading-kiln-a06d0b into master

@jjpaulino jjpaulino self-assigned this Nov 11, 2026
Conflict in CLAY-VITE.md: kept master's CSS wording from #277 and
this branch's template output wording.
@jjpaulino
jjpaulino merged commit 7d0d908 into master Nov 16, 2026
1 check passed
@jjpaulino
jjpaulino deleted the jordan/template-js-loading-kiln-a06d0b branch November 16, 2026 20:07
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.

2 participants