Language

Saving a theme = registering a new version

Why not edit in place: startup replay, snapshots pinned by version + digest, and an immutable directory — three things stacked into the only way out.

What the theme editor does on save is not "change files" but register a higher version. This sentence is the cell most likely to be tripped over in the whole theme lifecycle, so let me explain why it is designed this way — once you understand the reason, you will not try to "fix" it.

Three things stacked together decide this shape. First, the built-in theme replays the version number it declares from the copy embedded in the binary at every startup. So landing your changes on the same version number is writing something that will be overwritten at the next startup. The conclusion is not "the built-in theme is read-only", but the built-in theme can be changed, only into a new version higher than the embedded one. This cell is not redundant validation: the store may only register a lower version (the binary was upgraded, or only the database was moved without the theme directory), and such a version number would pass "higher than what the store registers", yet the version that passed gets re-eaten at the next startup anyway. Second, publish snapshots pin themes by "theme identifier + version + content digest". Changing bytes in place makes the old snapshot's digest mismatch; the system would either degrade to the official default docs or be forced to rewrite that column — both make "which version are visitors seeing now" unanswerable. Third, the version directory is immutable by product contract.

The version number has only one owner. The save request has no "new version number" parameter; the "bump a version" on the UI edits the version text in the manifest, bumping only the revision number by default. When a second declaration appears, the two are bound to drift.

To touch the built-in theme, go through "copy". Copying the built-in theme into a new non-built-in theme is the only entry for editing it. This is not a permission restriction but an identity one: the built-in theme's name and identifier belong to the product, and changing it means changing the replay baseline at the same time.

The editor's file list comes from the declaration in the store. Which files GET …/files returns as editable is the result of building paths from the current version manifest and checking symlinks one by one; on submit, paths must also be in the baseline declaration — using the manifest you submit as the criterion would allow "submitting a file that does not exist while changing the manifest to include it". Binary assets (images, fonts) are visible in the tree but not clickable: the interface honestly returns editable=false with a reason, instead of giving a button that fails when clicked. Deleting files by changing the manifest also fails, blocked by "file set mismatch" — bytes still on disk while absent from the declaration is an intermediate state.

Template syntax errors return 422, not 400 and not 500. The request shape is fully correct and what fails is the theme's own syntax gate; mixing it into 400 makes people think the form was filled wrong, and returning 500 makes people think the server is broken. The response is "site copy first + server original in parentheses": sending only the original turns the Chinese UI into English, and sending only the site copy loses "which cell exactly".

After changing the CSS, publish once before visitors get it. This must be said plainly: saving a version is only registration, and the snapshot still pins the old theme version. The side effect should also be known — published old-visitor pages keep the old styles until republishing; that is the price of "which version visitors see" being answerable.

The audit does not record theme file bodies. Saving and copying each log one entry, with fields for the theme identifier, baseline, new version, digest, number of changed files, whether activated, and the operator. Reason: the audit is kept long-term and is queryable by everyone in the backend, and it travels with the archive, while templates and CSS contain things like customer brand colors and internal page structure.