From 35cbf96cbcfd7c24c5588df8bc887722b4e110d6 Mon Sep 17 00:00:00 2001 From: Chris Tse <2302191+christse@users.noreply.github.com> Date: Fri, 24 Jul 2026 12:09:47 -0400 Subject: [PATCH] Fix default templates crashing when card model is transiently undefined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default isolated/edit template derived the card class from model.constructor inside tracked getters. The host can render a format component for a tick while the model instance is still resolving (initial load, or a store re-resolve after an incremental index invalidation lands under an open card), which crashed the render with "Cannot read properties of undefined (reading 'constructor')". The class is already passed to every format component as @cardOrField — head.gts and embedded.gts use it for exactly this reason — so take it from there instead of digging it out of the instance. Same rework in field-edit.gts, which had the identical pattern. Guard the remaining @fields dereferences and render the CardInfo edit header and notes footer only when @fields is populated, so a render pass with no data produces an empty shell instead of throwing. Co-Authored-By: Claude Fable 5 --- .../base/default-templates/field-edit.gts | 5 +-- .../default-templates/isolated-and-edit.gts | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/base/default-templates/field-edit.gts b/packages/base/default-templates/field-edit.gts index 0bdbaec7ce8..e465a23af52 100644 --- a/packages/base/default-templates/field-edit.gts +++ b/packages/base/default-templates/field-edit.gts @@ -1,5 +1,5 @@ import GlimmerComponent from '@glimmer/component'; -import type { FieldDef } from '../card-api'; +import type { BaseDef, FieldDef } from '../card-api'; import { FieldContainer } from '@cardstack/boxel-ui/components'; import { eq } from '@cardstack/boxel-ui/helpers'; import { startCase } from 'lodash-es'; @@ -7,12 +7,13 @@ import { getField } from '@cardstack/runtime-common'; export default class FieldDefEditTemplate extends GlimmerComponent<{ Args: { + cardOrField: typeof BaseDef; model: FieldDef; fields: Record GlimmerComponent>; }; }> { getFieldIcon = (key: string) => { - return getField(this.args.model.constructor, key)?.card?.icon; + return getField(this.args.cardOrField, key)?.card?.icon; };