Skip to content

feat: replace generated cache-key headers with content comparison - #37

Merged
ElMassimo merged 6 commits into
mainfrom
no-cache-key
Oct 19, 2026
Merged

ElMassimo merged 6 commits into
mainfrom
no-cache-key

Conversation

@ElMassimo

@ElMassimo ElMassimo commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Description 📖

This pull request removes cache-key headers from generated types to reduce merge conflicts. Identical content is left untouched, preserving file modification times.

It also limits development regeneration to modified serializers and their dependent subclasses and flat associations.

Background 📜

Cache-key headers can change without meaningful changes to the generated TypeScript. Content comparison avoids this churn and also restores files edited by hand.

Rails unloads serializers before reload callbacks, so incremental generation must load unchanged dependents too; otherwise their inherited or flattened attributes remain stale.

Upgrade ⚙️

Run bin/rake types_from_serializers:generate once after upgrading to remove existing headers. SERIALIZER_TYPES_FORCE now only controls output-directory cleanup.

The TypesFromSerializers.force_generation reader is removed.

ElMassimo and others added 6 commits October 17, 2026 12:58
Generated files no longer start with a '// TypesFromSerializers CacheKey'
line. The line was an MD5 of the serializer's properties, used to skip
rewriting files that had not changed, but it caused merge conflicts
whenever two branches touched the same serializer. Files are now rendered
and compared with what is on disk, and written only when they differ.

In development, generate_changed uses the listen tracker to decide what to
do: when serializer files were only modified, just those get required and
their interfaces regenerated, without loading every serializer; added or
removed files trigger a full pass so the index stays accurate.

The spec suite now gives each example its own config copy, so the
namespace example no longer leaks into later ones.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Rails unloads every class before to_prepare, so requiring only the
modified serializer files left their subclasses and flat associations
unloaded, and their generated interfaces stale, until a full pass ran.

generate_changed now also requires every serializer file that mentions a
serializer defined in the modified files, transitively, by scanning the
files for the names. That over-approximates (plain association references
qualify too) at the cost of loading a few extra files, which is still far
cheaper than loading every serializer on each change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Plain associations import the other interface by name, so their output
doesn't change when the associated serializer does. Matching only
inheritance and flat embeds keeps a modification from loading every
serializer that happens to mention a common name.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ElMassimo
ElMassimo merged commit 1902824 into main Oct 19, 2026
5 checks passed
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.

1 participant