Skip to content

Realm-index opt-in for prerendered isolated HTML#4769

Open
habdelra wants to merge 6 commits into
mainfrom
indexer-perf/realm-index-opt-in
Open

Realm-index opt-in for prerendered isolated HTML#4769
habdelra wants to merge 6 commits into
mainfrom
indexer-perf/realm-index-opt-in

Conversation

@habdelra
Copy link
Copy Markdown
Contributor

@habdelra habdelra commented May 11, 2026

Summary

Adds a realm-level opt-in for keeping the prerendered isolated HTML of the default CardsGrid realm-index card. When the opt-in is not set, the host substitutes a small boilerplate placeholder for the isolated render of that specific card and skips the (expensive) grid fan-out render of every card in the realm. Stands alone — strictly does less work, no parallelism.

  • New optional field includePrerenderedDefaultRealmIndex on the RealmConfig CardDef and on RealmInfo.
  • parseRealmInfo extracts the field from both the disk-overlay and indexed-overlay paths that already populate name / backgroundURL / iconURL.
  • packages/host/app/routes/render/html.ts flags useRealmIndexBoilerplate on its model when:
    • format === 'isolated', ancestor_level === 0
    • The card's id matches the realm's default index (isRealmIndexCardId)
    • The type chain begins with the base CardsGrid ref (via internalKeyFor comparison)
    • RealmInfo.includePrerenderedDefaultRealmIndex !== true
  • packages/host/app/components/card-prerender.gts short-circuits the Glimmer render when the flag is set and returns a static boilerplate constant instead.
  • New constant REALM_INDEX_BOILERPLATE_HTML in packages/host/app/utils/realm-index-boilerplate.ts. Wrapped in a <section data-prerender>...</section> so it's structurally consistent with what withTimeout captures from a real render. The placeholder text names the configuration knob so anyone who lands on it knows where to flip it.

Why this matters

The CardsGrid isolated render is a significant single cost in a from-scratch reindex on /prudent-octopus (about 10s of the 190s baseline) and scales linearly with realm size — its isolated template renders a fitted view of every card in the realm. Today nothing in the search-result hot path consumes the realm-index isolated HTML; the only production readers are:

  • The published-realm SSR injection (retrieveIsolatedHTML in packages/realm-server/server.ts:483).
  • The lastKnownGoodHtml error fallback for an erroring realm-index card.

Both are narrow paths. Unpublished realms never need the isolated render at all.

The field stays unused for now

No production realm currently sets includePrerenderedDefaultRealmIndex: true. The field is a future-lever and is wired up automatically for published realms by the next PR in the stack (#4770 — publish handler writes the field into the published snapshot's realm.json when its index is the default CardsGrid).

The boilerplate

<section data-prerender>
  <div class="boxel-cards-grid-shell" data-boxel-cards-grid-index aria-busy="true">
    Prerendered HTML for default realm index is disabled (can be configured in realm.json)
  </div>
</section>

Goals:

  • Valid HTML the browser can paint and Ember can replace cleanly on hydration.
  • Structurally consistent with real captures so downstream code paths (SSR injection, error fallback) don't have to special-case null.
  • Self-documenting — the visible text names the realm.json field, so any operator who briefly sees it knows the knob.

RealmInfo field is optional

RealmInfo.includePrerenderedDefaultRealmIndex is typed as boolean | null | undefined to avoid forcing every fixture across runtime-common / host / realm-server test suites to add the field. Production code never relies on its presence — only on === true.

Test plan

  • pnpm lint:types clean in @cardstack/runtime-common and @cardstack/host and @cardstack/realm-server.
  • pnpm lint:js clean for files this PR touches.
  • Integration test: index a realm whose index.json is default CardsGrid → isolated_html row equals REALM_INDEX_BOILERPLATE_HTML; other formats render normally.
  • Integration test: same realm with includePrerenderedDefaultRealmIndex: true in realm.jsonisolated_html contains a full rendered grid (verifies the lever works even though no production realm uses it today).
  • Integration test: realm with a custom (non-CardsGrid) index card → isolated_html renders normally regardless of the field.

🤖 Generated with Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f542487809

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/host/app/routes/render/html.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a realm-level opt-in to keep (or skip) prerendered isolated HTML for the default CardsGrid realm-index card, allowing the host to substitute boilerplate and avoid expensive grid fan-out renders when not needed.

Changes:

  • Introduces includePrerenderedDefaultRealmIndex on RealmConfig/RealmInfo and parses it from both disk and index overlays.
  • Adds host-side detection of the default CardsGrid index isolated render and passes a useRealmIndexBoilerplate flag through the render route model.
  • Short-circuits prerendering to return a new REALM_INDEX_BOILERPLATE_HTML constant when the flag is set.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/runtime-common/realm.ts Adds/propagates the opt-in field into RealmInfo and realm config parsing to inform host behavior.
packages/host/app/utils/realm-index-boilerplate.ts Introduces the static boilerplate HTML returned when isolated render is skipped.
packages/host/app/routes/render/html.ts Detects the default CardsGrid realm index isolated render and sets useRealmIndexBoilerplate in the route model.
packages/host/app/components/card-prerender.gts Returns boilerplate HTML instead of running Glimmer when useRealmIndexBoilerplate is set.
packages/base/realm-config.gts Adds the opt-in field to the RealmConfig card schema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/host/app/routes/render/html.ts Outdated
Comment thread packages/host/app/components/card-prerender.gts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Preview deployments

Host Test Results

    1 files  ±0      1 suites  ±0   2h 6m 25s ⏱️ + 2m 46s
2 657 tests ±0  2 641 ✅  - 1  15 💤 ±0  0 ❌ ±0  1 🔥 +1 
2 676 runs  ±0  2 659 ✅  - 2  15 💤 ±0  1 ❌ +1  1 🔥 +1 

Results for commit fedf974. ± Comparison against earlier commit 86eaecf.

For more details on these errors, see this check.

Realm Server Test Results

    1 files  ±0      1 suites  ±0   12m 46s ⏱️ -9s
1 321 tests ±0  1 321 ✅ + 9  0 💤 ±0  0 ❌  -  9 
1 400 runs  ±0  1 400 ✅ +14  0 💤 ±0  0 ❌  - 14 

Results for commit fedf974. ± Comparison against earlier commit 86eaecf.

habdelra and others added 3 commits May 11, 2026 17:48
Adds an `includePrerenderedDefaultRealmIndex` field to RealmConfig
that controls whether the host's render route produces a full
prerendered isolated HTML for the realm's default CardsGrid index
card. When the field is unset (the default), the host substitutes a
small boilerplate placeholder for the isolated render of that
specific card and skips the (expensive) grid fan-out render of every
card in the realm.

Why this matters: the CardsGrid isolated render is the second-largest
single cost in a from-scratch reindex — its isolated template renders
a fitted view of every card in the realm, so cost scales linearly
with realm size (17.3s on a 100-card realm, proportionally bigger on
500+ cards). Today nothing in the search-result hot path actually
consumes the realm-index isolated HTML; the only production consumers
are the published-realm SSR injection (`retrieveIsolatedHTML` in
server.ts) and the `lastKnownGoodHtml` error fallback. Unpublished
realms never need it.

The field stays as a future-lever for now. No production realm sets
it. The published-realm path that genuinely needs the full render is
addressed in a follow-on PR that writes the field on the published
realm snapshot at publish time.

Detection lives in `packages/host/app/routes/render/html.ts`: when
`format === 'isolated'` AND the card is the realm's index AND the
type chain begins with base CardsGrid AND
`RealmInfo.includePrerenderedDefaultRealmIndex !== true`, the route's
model carries a `useRealmIndexBoilerplate` flag. The orchestrator in
`card-prerender.gts` honours the flag by returning the boilerplate
constant directly, bypassing Glimmer rendering entirely.

The boilerplate matches the `<section data-prerender>...</section>`
shape that real renders capture, so downstream consumers (the SSR
injection slot, error-page fallback, anything reading `isolated_html`
directly) see structurally consistent content. The placeholder text
calls out that the lever is configurable in realm.json so an operator
who lands on it knows where to flip it.

The new `RealmInfo.includePrerenderedDefaultRealmIndex` is optional in
the type so the dozens of `RealmInfo` fixtures across the host /
runtime-common test suites don't all have to update. `parseRealmInfo`
reads the field from both the disk-overlay and indexed-overlay paths
that already exist for `name` / `backgroundURL` / `iconURL`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Covers the three meaningful branches of the host's render-route
detection:

1. Default CardsGrid realm-index card with no opt-in → isolated HTML
   row equals the boilerplate constant; embedded / fitted HTML maps
   still render normally.
2. Default CardsGrid realm-index card with the opt-in set via
   realm.json → isolated HTML is fully rendered (not the boilerplate).
   Exercises the future-lever code path even though no production
   realm uses it today.
3. Realm whose index.json is a custom (non-CardsGrid) card → isolated
   HTML renders normally regardless of the opt-in. Confirms the
   detection only triggers for the default-grid case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… cast

Two Copilot review findings on the realm-index detection:

- `BASE_CARD_INTERNAL_KEY` guard in
  `routes/render/html.ts#isDefaultRealmCardsGridIndex` was
  unreachable. After the previous check confirms
  `topKey === CARDS_GRID_INTERNAL_KEY`, asking again whether it
  equals the (different) base-card key can never fire. Removed the
  guard and the unused constant.
- The inline cast on `routeInfo.attributes` in
  `card-prerender.gts` weakened type safety. Import the html
  sub-route's `Model` type directly and cast through it instead, so
  the route model and the consumer can't silently drift apart.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@habdelra habdelra force-pushed the indexer-perf/realm-index-opt-in branch from 7cde395 to 5a2fa61 Compare May 11, 2026 21:50
@habdelra habdelra changed the base branch from indexer-perf/parallel-visit-loop to main May 11, 2026 21:50
@habdelra
Copy link
Copy Markdown
Contributor Author

[Claude Code]

Rebased this PR onto origin/main directly so it can land independently of PR #4767 (the parallelism PR, which is being parked for further investigation — benchmarks showed parallelism causes a self-referential prerender deadlock on realms with query-backed linksToMany aggregator cards).

This PR is now structurally simple — it's purely the realm-index opt-in lever. Files changed:

packages/base/realm-config.gts                      (+12)
packages/host/app/components/card-prerender.gts     (+16)
packages/host/app/routes/render/html.ts             (+67/-3)
packages/host/app/utils/realm-index-boilerplate.ts  (new)
packages/host/tests/integration/realm-indexing-test.gts (+146)
packages/runtime-common/realm.ts                    (+24)

No index-runner.ts changes. Strictly does less work — skips the (expensive) isolated render for the default CardsGrid realm-index card when the realm hasn't opted in. CI failures from the earlier stacked SHA were inherited from PR1's parallelism regression; the fresh CI run on 5a2fa61f should be clean.

habdelra and others added 3 commits May 11, 2026 18:53
testRealmInfo (both runtime-common/helpers/const.ts for host tests and
realm-server/tests/helpers/index.ts for realm-server tests), plus
every inline realmInfo fixture in realm-indexing-test.gts and
realm-test.gts, now carries includePrerenderedDefaultRealmIndex:
false. The realm-config card's BooleanField defaults to false, so
that's the value the /_info handler emits when the opt-in is unset —
and assertion targets need to match that.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A test realm with no realm.json (RealmConfig card) and no
.realm.json sidecar leaves includePrerenderedDefaultRealmIndex at
the initial null value parseRealmInfo seeds — none of the three
overlays (sidecar, on-disk card, indexed card) fires when the
underlying file is absent. The earlier fixture-update commit
read the BooleanField emptyValue and used false, but that value
is only observable when an actual RealmConfig card is indexed.
For the integration tests' setupIntegrationTestRealm contents
that omit realm.json, the response carries null, so realmInfo
assertions need to match.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The realm-server test realm (tests/cards/) ships with a realm.json
RealmConfig card on disk that gets indexed before tests run, so the
indexed-card overlay in parseRealmInfo emits the BooleanField's
emptyValue (false) for includePrerenderedDefaultRealmIndex.

The host integration tests in runtime-common/helpers/const.ts stay at
null because those realms have neither a sidecar nor a RealmConfig card,
so none of the parseRealmInfo overlays touch the seeded null.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@habdelra habdelra requested a review from a team May 12, 2026 02:48
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