Lightweight render.types route; drop double serializeCard+searchDoc#4928
Open
habdelra wants to merge 1 commit into
Open
Lightweight render.types route; drop double serializeCard+searchDoc#4928habdelra wants to merge 1 commit into
habdelra wants to merge 1 commit into
Conversation
The prerender runner needed the ancestor type chain before driving the fitted/embedded format renders, but the only way to obtain it was a full /render/.../meta call that also paid for serializeCard + searchDoc — work the runner threw away. The fitted/embedded renders are what mark linksTo / linksToMany fields as "used", so a single render.meta after them produces the correct search doc; the earlier call was structurally wasted per-card wall-clock on the host's main thread. Add a sibling /render/.../types route that returns only the type chain (getClass + getTypes), and call it for the first pass. The final render.meta still runs after the format renders, preserving the isUsed-via-non-isolated-render contract that `non-isolated formats render linked fields and those links appear in search doc` covers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces per-card prerender overhead by introducing a lightweight host route that returns only a card’s ancestor type chain, avoiding an extra serializeCard + searchDoc traversal that was previously done solely to obtain meta.types.
Changes:
- Add
/render/:id/:nonce/:options/types(host) to return only the ancestor type chain. - Update the realm-server prerender runner to call
render.typesfor the first pass and keep a singlerender.metacall for the final (post-ancestor-render) metadata capture. - Introduce a shared
PrerenderTypespayload type in@cardstack/runtime-common.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/runtime-common/index.ts | Adds the PrerenderTypes interface for the new lightweight prerender payload. |
| packages/realm-server/prerender/utils.ts | Adds renderTypes() capture helper to drive the new /types route. |
| packages/realm-server/prerender/render-runner.ts | Switches the runner’s first pass from render.meta (types) to render.types. |
| packages/host/app/templates/render/types.gts | Adds a template that JSON-prints the render.types model. |
| packages/host/app/routes/render/types.ts | Adds the new host route that computes and returns the ancestor type chain only. |
| packages/host/app/router.ts | Registers the new render.types route. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lukemelia
approved these changes
May 21, 2026
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.
Stacked on #4926 (parent ticket CS-11208). Linear: CS-11237.
Summary
/render/.../metatwice per card. The first call existed only to read the ancestor type chain so the fitted/embedded format renders could be driven; the second captured the realserialized + searchDoc + deps + displayNamesafter those renders marked linked fields as "used".serializeCard({includeComputeds:true}) + searchDoc(instance)walk every time, even though the runner consumed onlymeta.types./render/:id/:nonce/:options/typesthat returns only the type chain (getClass+getTypes). The runner calls it for the first pass and keeps/metafor the final pass.render.metastill runs after the fitted/embedded ancestor renders, preserving the isUsed-via-non-isolated-render contract that thenon-isolated formats render linked fields and those links appear in search doctest inpackages/realm-server/tests/prerendering-test.tscovers.Why this is safe
The previous attempt in the parent PR collapsed both calls into one and broke that test: a single
render.metabefore the embedded/fitted renders meant linksTo / linksToMany fields had not yet been marked "used", so the search doc walk missed them. This change does the opposite — it keeps the secondrender.metaexactly where it was (after the format renders) and replaces only the cheap first call with a route that returns the type list and nothing else.No new module-state in
card-api. No changes required in user realms.Expected impact
renderElapsedMsper card prerender drops by roughly the wall-clock of oneserializeCard + searchDocon that card type — ~60–80ms for the heaviest cards measured under the parent ticket. Compounds across from-scratch reindex of a multi-file realm.Test plan
non-isolated formats render linked fields and those links appear in search docinpackages/realm-server/tests/prerendering-test.tspasses.renderElapsedMsdistribution shifts down vs. parent branch.🤖 Generated with Claude Code