Skip to content

Optional-chain arguments are evaluated eagerly in inferred hook and SSR prop dependencies #1799

Closed

Description

@jpg-oai

The dependency collectors can evaluate an argument or computed key even when an optional chain skips it.

Reproduced with the compiler and server runtime sources at 676a4ee6db59854d6b711921f4ac808845dcdbcd (0.7.1). The relevant collector logic is also present on current main; I have not qualified the current main runtime.

Minimal authored example:

function Result({ value }) @{ <p>{value as string}</p> }
export function App({ run, options }) @{
  <Result value={run?.(options.label) ?? 'idle'} />
}

Compile this with compile(source, 'example.tsrx', {mode: 'server', dev: false}), load the generated module, and call renderToString(App, {run: undefined, options: undefined}).

Expected: <p>idle</p> (with normal hydration metadata). Actual: an exception reading options.label from the generated eager prop-memo dependency array. A throwing options.label getter demonstrates the same skipped-read violation. The analogous useMemo(() => run?.(options.label) ?? 'idle') fails in the client and plain-hook transforms too. Optional computed access, such as value?.[options.key], needs the same protection.

There are two owners:

  • collectDependencies in src/compiler/hook-deps.js traverses optional call arguments as unconditional reads.
  • collectDepPaths in src/compiler/compile.js does the same for warmed SSR prop creation memos.

A focused repair keeps receiver reads precise, walks optional-chain arguments/computed keys under their guard, and uses the existing guarded __methodDep descriptor probe for skipped member reads. This avoids invoking getters just to construct a dependency array.

I extended the existing guarded-hook fixture and runtime/hydration owners. Six regression cases fail before the repair; all 97 selected guarded-hook and dependency-compiler cases pass afterward. Coverage includes undefined/null receivers, skipped argument/key getters, SSR-to-client adoption, retained DOM, transitions to/from a receiver, same-object own-field changes, and plain hooks. This is source-runner DOM qualification, not a physical-browser claim.

Activity

  1. added a commit that references this issue on Oct 6, 2026
    087cd77
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