Skip to content

tanstack: defaultCellRenderers has a "datetime" key with no registered view.datetime subtype #355

Closed

Description

@dmealing

Package: @metaobjectsdev/tanstack 0.24.5 (renderer registry) vs. @metaobjectsdev/metadata 0.24.5 (view subtype registry)

What's wrong

@metaobjectsdev/tanstack's cell-renderers.tsx registers defaultCellRenderers, keyed by a column's meta.view (populated at codegen time from a field's declared view.* subtype):

export const defaultCellRenderers: Record<string, CellRenderer> = {
  text:     ...,
  textarea: ...,
  number:   ...,
  date:     (ctx) => { ... return v ? new Date(v as string).toLocaleDateString() : ""; },
  datetime: (ctx) => { ... return v ? new Date(v as string).toLocaleString() : ""; },
  boolean:  ...,
  currency: ...,
  dropdown: ...,
  password: ...,
};

But @metaobjectsdev/metadata's registered view.* subtypes (presentation/view/view-constants.ts) are exactly:

base, text, textarea, date, month, hotlink, dropdown, radio, checkbox, number, password, hidden, web, currency, image

There is no view.datetime subtype anywhere in the registry. Since a column's meta.view is always one of the registered view subtypes (there is no other way to populate it via codegen), the datetime key in defaultCellRenderers can never be selected through normal metadata-driven codegen — it's reachable only if application code hand-sets a column's meta.view to "datetime" outside the generated pipeline.

Consequence

A field.timestamp-typed field that should render both a date and a time of day has no matching view subtype to declare. Its only registered option is view.date, whose default renderer is toLocaleDateString() — which drops the time component entirely. An application that wants correct timestamp rendering must either:

  • accept the default and silently lose the time-of-day, or
  • override the date renderer key itself to render date+time, quietly absorbing the responsibility that the presence of a distinct, unreachable datetime key implies should be a separate, dedicated concern.

Either way, the registered vocabulary (view.date only) and the renderer registry (date and datetime) disagree about how many concerns exist here, and only one of the two ever actually reflects real dispatch.

Suggested fix

Either:

  1. Register a view.datetime subtype in @metaobjectsdev/metadata (mirroring how date and month are already distinguished) so fieldViewKind() can select it for timestamp-typed fields and defaultCellRenderers.datetime becomes reachable, or
  2. Remove the unreachable datetime key from defaultCellRenderers and document that view.date's renderer is expected to carry time-of-day rendering whenever it backs a timestamp-typed field, so there's one registered vocabulary term instead of two that disagree.

Activity

  1. dmealing commented on Aug 31, 2026

    @dmealing
    MemberAuthor

    Fixed on main; ships in the next release — and the report understates it by one. Cross-checking the renderer keys against the registered subtypes mechanically:

    registered view subtypes: base, text, textarea, date, month, hotlink, dropdown,
                              radio, checkbox, number, password, hidden, web, currency, image
    renderer keys:            text, textarea, number, date, datetime, boolean, currency,
                              dropdown, password
    UNREACHABLE:              ['boolean', 'datetime']
    

    boolean is dead too — and that half is the one that cost something, because of the inverse gap the issue doesn't mention: view.checkbox IS registered and had no renderer at all. So a checkbox column fell through if (!renderer) return col; and rendered a raw true/false, while the "Yes"/"No" renderer plainly written for it sat under the unreachable boolean key. The renderer existed, the column existed, and the two could never meet.

    Renaming that key to the registered subtype is the whole fix for that half.

    On the two options offered: option 2, with the reasoning slightly different from how it's framed. datetime is deleted rather than registered, because the distinction the key implies is already carried by the field subtype — field.timestamp and field.date are different declared types — so a new view.* subtype would be new vocabulary for a distinction the model already makes, at the cost of moving metamodelVersion and obliging all four registries to publish.

    A timestamp that should show time-of-day is served by overriding the date key through CellRendererProvider, which already works. The metaobjects-runtime-ui skill now says so explicitly — replacing a sentence that listed boolean among the selectable keys, i.e. a shipped doc that was teaching one of the dead ones.

    The missing check is the durable part, and it now exists: a gate asserts every renderer key is a registered view subtype. It lives in codegen-ts-tanstack rather than the browser package, because @metaobjectsdev/tanstack deliberately carries no @metaobjectsdev/metadata dependency (#287 made a single value import from that package's root unbundlable) and the codegen package is the one that decides what meta.view can say.

    One note for anyone who had overridden the boolean key: that override was already dead, since no column could ever carry meta.view: "boolean". Re-key it to checkbox.

  2. dmealing commented on Sep 1, 2026

    @dmealing
    MemberAuthor

    Follow-up on main in 25a7772 — this closed the other direction of the same gap.

    The fix here asserted renderer key → registered subtype, which catches a dead key like
    datetime. The converse was never asserted, and that is the half checkbox actually lived in:
    EntityGrid does if (!renderer) return col, so a registered subtype with no key falls
    through to TanStack's default cell and prints the raw value, whatever the subtype's own
    registered description promises. Five concrete subtypes were in that state.

    • view.hidden — registered as "Not rendered; carried but not shown", and it rendered
      its value. The generated form has always honoured it (<input type="hidden">); the grid
      contradicted it outright. The column is now dropped at codegen in both grid tiers rather
      than given a blank-cell renderer — a blank cell still holds a header and a sort target, so
      the value would be hidden while the column was not. Dropped even when @columns names the
      field: that and view.hidden contradict each other, and the one about rendering is the
      specific answer to the question a grid asks. (Sorting by such a field still works —
      defaultSort goes to the fetcher's query params, not the column model.)
    • view.hotlink — "Renders the value as a clickable link", rendering plain text. Now an
      anchor, with the scheme checked: the cell value comes from the database, so an anchor built
      blindly from a stored string is a javascript: URL away from executing on click. Anything
      not http/https/mailto renders as text — which is what it did before, so the guard can only
      ever be safe.
    • view.month — rendered the raw stored string. Now a formatted month, parsed field-wise:
      new Date("2026-09") is UTC midnight and shows the PREVIOUS month to every viewer west of
      Greenwich. Asserted under a negative-offset timezone.
    • view.radio — keyed explicitly to dropdown's rendering, so that is recorded rather
      than an accident of the fall-through.
    • view.image — deliberately left with no default renderer. The field stores an opaque
      storage key, so an <img> needs ImageUploadAdapter.imageUrl(), exposed through a React
      context in @metaobjectsdev/react — which @metaobjectsdev/tanstack does not depend on.
      Adding that dependency drags the image-upload/crop graph into every grid consumer's bundle,
      the runtime-web/tanstack: browser bundling fails — root barrel transitively imports node:url (fileURLToPath) #287 / react-easy-crop class already fixed twice here. The clean version is a
      @metaobjectsdev/react subpath export, and 0.21.5 already deferred that /image split to
      a MINOR — so it belongs with that work, not inside a patch. Apps override the image key on
      <CellRendererProvider> today.

    The durable part is the converse gate: every concrete view subtype must now have a renderer
    OR a written exemption naming why, and a second test fails any exemption that outlives the gap
    it explains or names a subtype that does not exist. A missing key was an accident; an exemption
    is a decision on the record.

    Found while fixing #357 — making all 15 view.* subtypes discoverable to an author is what
    made "and what does the grid do with them?" a question worth asking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions