Repository navigation
feat: replace generated cache-key headers with content comparison - #37
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:generateonce after upgrading to remove existing headers.SERIALIZER_TYPES_FORCEnow only controls output-directory cleanup.The
TypesFromSerializers.force_generationreader is removed.