Repository navigation
Description
memo can retain stale output when one own prop is removed and a different prop is added. For example, replacing { toString: Object.prototype.toString } with { label: 'updated' } leaves the child displaying fallback instead of updated.
Environment
Unmodified Octane source 0.4.2, revision c25a18503ea30b27db09c3f60ff6b34afdfaf650; Node 22.22.2, pnpm 11.15.1, Vitest 4.1.10, jsdom 30.0.1, macOS 26.6.2 arm64. Reproduced in the default Vitest runtime and with NODE_ENV=production. No browser-only APIs are involved; a real browser and published npm artifact were not tested.
Reproduction
In a checkout of that revision, install the frozen dependencies:
pnpm install --frozen-lockfile --ignore-scripts --filter octane --filter . --filter @octanejs/stylexThe executed installation also used --offline with a populated pnpm store. Save this standalone config at the repository root as evidence.vitest.config.mjs:
import { defineConfig } from 'vitest/config';
import { octane } from './packages/octane/src/compiler/vite.js';
process.env.OCTANE_COMPILE_FROZEN_AST ??= '1';
process.env.OCTANE_COMPILE_ASSERT_LOC ??= '1';
export default defineConfig({
plugins: [octane({ hmr: false })],
test: { environment: 'jsdom', include: ['packages/octane/tests/**/*.test.ts'], setupFiles: ['packages/octane/tests/_per-test-setup.ts'], env: { OCTANE_TEST_COMPILE_MODE: 'prod' }, globals: false, testTimeout: 30000, maxWorkers: 2 },
});Save this test as packages/octane/tests/evidence-memo-minimal.test.ts:
import { expect, it } from 'vitest';
import { createElement, createRoot, flushSync, memo } from 'octane';
it('updates memo when an own toString prop is replaced by label', () => {
const Label = memo((props: { label?: string }) =>
createElement('output', null, props.label ?? 'fallback'));
const App = (props: { childProps: object }) => createElement(Label, props.childProps);
const container = document.createElement('div');
document.body.append(container);
const root = createRoot(container);
try {
root.render(App, { childProps: { toString: Object.prototype.toString } });
expect(container.textContent).toBe('fallback');
flushSync(() => root.render(App, { childProps: { label: 'updated' } }));
expect(container.textContent).toBe('updated'); // Actual: "fallback"
} finally {
root.unmount();
container.remove();
}
});Run:
pnpm exec vitest run --config evidence.vitest.config.mjs packages/octane/tests/evidence-memo-minimal.test.tsExpected: updated. Actual: fallback.
Evidence and impact
A broader eight-case matrix was repeated in three separate processes, including one with NODE_ENV=production. Each run produced the same three failures and five passing controls:
- Replacing an own
toString,constructor, orvalueOfprop whose value equals the correspondingObject.prototypevalue with{ label: 'updated' }leaves stale output undermemo. - All three non-memo equivalents update correctly.
- Memo updates correctly when replacing an ordinary prop, or when the own
toStringvalue is a different function.
An independent repeat produced the same failures while all four nearby conformance/memo-bailout.test.ts cases passed. The smaller reproduction above was also executed separately. This is a narrow prop-key transition: both prop objects are new, ordinary object literals; there is no prototype mutation. It can suppress unrelated new prop values when their addition balances the removed key count. No last-good revision or introducing commit is claimed.
Cause
The documented default memo contract compares own enumerable keys.
In shallowEqualProps, the plain-object path checks whether the next props own a key only when the previous value is undefined. Here, b.toString resolves to the inherited method and passes Object.is. Each object has one enumerable key, so the count also matches despite their different key sets. tryMemoBail then skips the update.
Provenance
- Agent-authored report and reproduction.
Activity