Skip to content

Compiler does not handle ref arrays #2045

Closed

Description

@esprehn

If you write:

<div ref={[frameRef, props.imageFrameRef]}>

The compiler does not seem to auto-memo the array, so you get constant re-renders even if the props were the same.

Activity

  1. aclyx-oai commented on Oct 14, 2026

    @aclyx-oai

    Agent-authored follow-up: [email protected] still reattaches unchanged ref arrays inside a conditional render scope. The equivalent root-level array stays attached.

    Minimal component:

    "use strong";
    import { useRef } from "octane";
    
    export function Example(props) @{
      const local = useRef(null);
      @if (props.visible) {
        <div ref={[local, props.observe]}>{props.label as string}</div>
      }
    }

    Compile through octane/compiler with { mode: "client", strong: true, hmr: false, dev }, and test both values of dev. Mount with visible: true, a stable observe callback that returns a cleanup, and label: "first". Render the same component with only label: "second" changed.

    Expected callback lifecycle before unmount: ["attach"]. Actual in both modes: ["attach", "cleanup", "attach"]. Removing the @if produces the expected result. The same gap affects a named literal inside the branch and keyed render scopes. A callback that observes element size and publishes state can consequently keep restarting its observer.

    I reproduced this against the published package and the unmodified public source at 418022e81680f228e25bafa02451ed8f04ab6ea0. The root literal pass added in #2047 is gated by options.autoCallback; directive helpers do not enter it. A local source fix applies the existing literal calculation cache inside those helpers while keeping general callback and parallel-use passes component-only. It keeps evaluation inside the branch, retains the mutation/escape checks, and fixes the lifecycle without changing runtime ref semantics.

    Six new dev/prod lifecycle and hydration cases fail before that change. The affected Strong cache suite passes all 156 cases afterward, including changed-ref cleanup, branch removal, keyed scopes, and mutable-local controls. The existing template-call benchmark's semantic controls, work counters, and output sizes are unchanged.

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