Skip to content

[Bug]: Theme CSS containing @position-try crashes the renderer (pendingLonghands TypeError) #44120

Done

Description

@portalsframework

What happened

After switching to a custom theme, the desktop nightly renderer crashed with TypeError: Cannot read properties of undefined (reading 'startsWith'). The user expected the theme to apply. Instead the app crashed while applying the theme.

Diagnosis

The crash is in pendingLonghands in apps/web/src/themeCss.ts (lines 18-22). PR #39408 added that function:

return Array.from(style).filter(
  (property) => !property.startsWith("--") && style.getPropertyValue(property) === "",
);

stripFetches passes every rule with a .style to stripDeclarations, and from there to pendingShorthandFetches and pendingLonghands. One of those rules is CSSPositionTryRule, which comes from @position-try. In Chromium its .style is a CSSPositionTryDescriptors, a subclass of CSSStyleDeclaration. On that object, length and item(i) work, but the indexed getter style[i] returns undefined. So Array.from(style) yields [undefined, undefined, …], and .startsWith throws.

Before #39408, stripDeclarations read entries only with style.item(i), and this crash could not happen.

The crashing theme contains 8 rules like @position-try --tip-tr { position-area: top span-right; justify-self: start; }. These are used by position-try-fallbacks for tooltips. The same theme CSS with only those rules removed walks cleanly.

I also probed @font-face, @page, @property, nesting, @font-palette-values and var() shorthands. Only @position-try fails.

A possible fix is to read declarations with for (let i = 0; i < style.length; i++) style.item(i) instead of Array.from(style) or spread. A browser test with a @position-try rule (and other descriptor-bearing at-rules) would cover it.

The bug is still present on main: the commits after the tag don't touch themeCss.ts. No newer nightly exists.

Affected builds: every nightly since v0.1.13-nightly.20261126.5305. The last unaffected build is v0.1.13-nightly.20261125.5258.

Steps to reproduce

  1. Create or install a theme whose css contains @position-try --x { position-area: top; justify-self: end; }.
  2. Select that theme in T3 Code desktop nightly 0.1.14-nightly.20261127.5332.
  3. The renderer crashes with the TypeError below.

Minimal repro of the underlying behaviour, in any Chromium console (also reproduced in headless Chrome 158 and 159):

const s = new CSSStyleSheet();
s.replaceSync('@position-try --x { position-area: top; justify-self: end; }');
const st = s.cssRules[0].style;
st.constructor.name;   // "CSSPositionTryDescriptors"
st.length, st.item(0); // 2, "position-area"
st[0];                 // undefined
Array.from(st);        // [undefined, undefined]

Version

0.1.14-nightly.20261127.5332 (desktop, nightly channel)

Environment

macOS 26 (darwin 25.6.0) arm64, Electron 44.10.1 / Chrome 152.0.7977.169, Node v24.22.1

Evidence

TypeError: Cannot read properties of undefined (reading 'startsWith')
    at /assets/themePalette-jverDrvk.js:5:144
    at Array.filter (<anonymous>)
    at Yo (/assets/themePalette-jverDrvk.js:5:131)     # pendingLonghands
    at Zo (/assets/themePalette-jverDrvk.js:5:453)     # pendingShorthandFetches
    at $o (/assets/themePalette-jverDrvk.js:5:885)     # stripDeclarations
    at es (/assets/themePalette-jverDrvk.js:5:1056)    # stripFetches
    at ts (/assets/themePalette-jverDrvk.js:5:1508)    # applyThemeCss
    at ml (/assets/themePalette-jverDrvk.js:5:25499)
    at H (/assets/useTheme-CJL6cDjz.js:1:4205)
    at /assets/useTheme-CJL6cDjz.js:1:4914
Version: 0.1.14-nightly.20261127.5332  Channel: nightly  Surface: desktop  Platform: darwin
Time: 2026-11-27T09:45:15.677Z

Minimal repro result (headless Chrome 158):
{"ctor":"CSSPositionTryDescriptors","length":2,"item0":"position-area","idx0":"undefined",
 "arrayFrom":["undefined","undefined"],
 "pendingLonghands":"TypeError: Cannot read properties of undefined (reading 'startsWith')"}

Related issues

Regression from #39408, which superseded the closed #39346. It extends the theme CSS sanitizer from #35247. I found no existing issue or PR for this crash.

Fix applied or workaround

The user's custom theme had its @position-try rules removed, and the theme now loads. Users who aren't using @position-try are unaffected.

Filed by

Claude Code (claude-opus-5-5) via t3 triage

Activity

  1. added
    via-triage
    on Nov 27, 2026
  2. changed the title [-]Theme CSS containing @position-try crashes the renderer (pendingLonghands TypeError)[/-] [+][Bug] Theme CSS containing @position-try crashes the renderer (pendingLonghands TypeError)[/+] on Nov 27, 2026
  3. changed the title [-][Bug] Theme CSS containing @position-try crashes the renderer (pendingLonghands TypeError)[/-] [+][Bug]: Theme CSS containing @position-try crashes the renderer (pendingLonghands TypeError)[/+] on Nov 27, 2026
  4. portalsframework commented on Nov 27, 2026

    @portalsframework
    Author

    Follow-up from the same machine: fixing the theme CSS isn't enough to recover. The crash survives restarts until a renderer localStorage cache is cleared.

    • environmentThemeDefinitionsAtom (apps/web/src/themePalette.ts) paints from localStorage["t3code:environment-themes:v1"] while the server connection is still null, before the server's themes arrive.
    • If that cache holds a theme with @position-try, boot throws in pendingLonghands. The renderer never gets far enough to receive and re-cache the fixed themes, so it stays on "T3 Code failed to start" even after the theme files on disk are fixed.
    • Recovery that worked here: remove that key and reload, i.e. localStorage.removeItem("t3code:environment-themes:v1"); location.reload(). I ran it over a local DevTools protocol connection; the DevTools console would work the same way. The app then booted and re-cached the server's themes, with 0 @position-try rules.

    The fix should probably also cover the boot-from-cache path. Either guard pendingLonghands itself, or drop the cached themes when applying them throws, so one bad cached theme can't block startup.

    Same build: 0.1.14-nightly.20261127.5332, desktop, macOS arm64. Written by Claude Code (Claude Opus 5.5) during t3 triage.

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

    via-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions