Skip to content

Compiler JSX map eligibility invokes Proxy traps that native map never uses #2567

Closed

Description

@domgan-oai

Reproduction

Use Node 22.22.3 and Octane 0.17.0. Compile this file as List.tsrx for production SSR.

export function Probe({ rows }) @{
  <main>{rows.map((row, index) => <i key={index}>{row as string}</i>)}</main>
}
export function Block({ rows }) @{
  <main>{rows.map((row, index) => { return <i key={index}>{row as string}</i>; })}</main>
}

Run both compiled components with the same array.

import { renderToString } from 'octane/server';

const rows = new Proxy(['a', 'b'], {
  getPrototypeOf() {
    throw new Error('unexpected prototype read');
  },
});

rows.map(value => value);     // ['a', 'b']
renderToString(Block, { rows }).html; // includes <i>a</i><i>b</i>
renderToString(Probe, { rows });      // throws unexpected prototype read

Save this as repro.mjs beside List.tsrx and run NODE_ENV=production node repro.mjs.

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { compile } from 'octane/compiler';
import { renderToString } from 'octane/server';

const file = new URL('./List.tsrx', import.meta.url);
const { code } = compile(readFileSync(file, 'utf8'), file.pathname, { mode: 'server', dev: false });
const { Probe, Block } = await import(`data:text/javascript,${encodeURIComponent(
  code.replaceAll("'octane/server'", JSON.stringify(import.meta.resolve('octane/server'))),
)}`);

const rows = new Proxy(['a', 'b'], {
  getPrototypeOf() {
    throw new Error('unexpected prototype read');
  },
});

assert.deepEqual(rows.map((value) => value), ['a', 'b']);
assert.match(renderToString(Block, { rows }).html, /<i>a<\/i><i>b<\/i>/);
assert.throws(() => renderToString(Probe, { rows }), /unexpected prototype read/);
const custom = new Proxy(['a', 'b'], {
  get(target, key, receiver) {
    if (key === 'map') return callback => [callback('a', 0, target)];
    return Reflect.get(target, key, receiver);
  },
  getPrototypeOf() {
    throw new Error('unexpected prototype read');
  },
});
assert.deepEqual(custom.map(value => value), ['a']);
assert.match(renderToString(Block, { rows: custom }).html, /<i>a<\/i>/);
assert.throws(() => renderToString(Probe, { rows: custom }), /unexpected prototype read/);
console.log('Ordinary and custom methods work with the authored map. The fused form throws.');

Observed behavior

The expression-bodied form emits a runtime eligibility call to mapSlot before the original array method. The first Object.getPrototypeOf(receiver) check invokes the proxy's trap and throws. The block-bodied control retains the authored method call and renders both rows. Production Octane client rendering exhibits the same difference, and production React SSR renders both rows.

An additional logging proxy shows the guard's getPrototypeOf and property-descriptor probes and repeated reads of length. The authored native method reads map, length, and constructor, then observes each index with has and get.

Expected behavior

Fusion should preserve the receiver operations observable in the original map call. Ineligible or unproven receivers should use the existing authored callback and descriptor path. A source-proven plain receiver could retain the current fast path. Standard JavaScript provides no trap-free operation to distinguish an ordinary array from a proxy around it.

The failure occurs before the first callback, with an ordinal key and simple text. Issue #2458 concerns the order of key and row reads after callback lowering. Issue #2496 concerns a codemod rewrite that skips an overridden map. This example is compiler codegen for authored TSRX and the original native map method.

Custom-method subcase

The guard probes the receiver's prototype before comparing the captured method with the native map function. A proxy that supplies a custom method also fails unnecessarily. Moving the existing identity comparison before receiver reflection addresses this subcase in both runtimes without changing the native method's guard. The native-method proxy still needs a source proof or a different lowering.

The same failure is reproducible when the proxy supplies a custom method. Comparing the captured method to the native method before receiver checks would let that case use the existing authored callback path. A proxy using the native method remains a separate part of the receiver problem.

Codex task · com-79386

Activity

  1. added
    bug
    agent-authored
    on Nov 13, 2026
  2. domgan-oai commented on Nov 13, 2026

    @domgan-oai
    ContributorAuthor

    A source-proven array initializer does not prove that later state snapshots are ordinary arrays. The existing JSX list benchmark starts with a genuine [], then appends rows with setItems(d => d.concat(buildData(1000))). Array.prototype.concat honors Symbol.species, whose constructor can return a Proxy even when d has never escaped.

    const species = Object.getOwnPropertyDescriptor(Array, Symbol.species);
    Object.defineProperty(Array, Symbol.species, {
      configurable: true,
      get() {
        Object.defineProperty(Array, Symbol.species, species);
        return function Result(length) {
          return new Proxy(new Array(length), {
            getPrototypeOf() { throw Error('unexpected prototype read'); },
          });
        };
      },
    });

    In an isolated page, run the JSX benchmark’s Create 1,000 rows action, install the one-shot getter above, then click Append 1,000 rows. The getter restores the original intrinsic before rendering. A production client test using the unchanged benchmark source hit unexpected prototype read during the fused render. A control that only changed the map callback from an expression body to a block body rendered 2,000 rows. The same outcome holds when the compiler statically selects its existing authored-map fallback for that receiver.

    A direct array literal or a fixed local bound to one can establish ordinary receiver identity. The benchmark’s state receiver can still become a Proxy through its normal update path. A receiver-proof-only compiler change would have to send that site through the authored fallback, or use an explicit producer/runtime provenance contract. This is independent of evaluation order within the callback.

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

    agent-authoredbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions