Skip to content

fix(memo): compare own prop membership - #1279

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/fix-memo-own-props
Sep 23, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/fix-memo-own-props

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Default memo can retain stale output when an own prop such as toString: Object.prototype.toString is replaced by label: 'updated'. The old value comparison accepts the inherited method, and equal key counts hide the changed key set.

Require next props to own every compared key in the shared DOM comparator. Keep the allocation-free loops, prototype gate, and exact fallback. Add an octane patch changeset and behavioral coverage for template and value-position children, hydration, prototype names, and explicit undefined membership.

Universal comparisons already check ownership; server memo does not cache prop comparisons. Both have passing rendering controls. Null-prototype cases cover input handling: element APIs normalize those inputs before DOM comparison. __proto__ is a passing control rather than a pre-fix failure.

Fixes #1253.

Validation

  • Reproduced stale fallback output in 128 DOM regression cases before the fix, across development/production compilation and hydration.
  • Focused Vitest: 322 tests passed across memo-props, memo-value-position, conformance/memo-bailout, hook-fixes, and lazy-output, in development and production compile projects; at most two workers, no parallel files.
  • Production runtime: 121 memo-props tests passed with NODE_ENV=production in the worker and production compilation.
  • Scoped pnpm typecheck:files for source, test, and fixture.
  • Scoped pnpm format:files:check, pnpm changeset:check, and pnpm sync.
  • Repository-wide format, typecheck, and tests: deferred to CI. Local Vitest used a temporary focused config with the repository's Octane plugin and per-test setup because the filtered dependency install cannot load the full root config.

Risk / follow-ups

The ownership check adds CPU work per compared prop without adding allocations. An isolated actual-source Node 22.22.3 diagnostic used serial B-C-C-B processes, eight warmups, and 17 samples of 50,000 comparisons. Five equal plain-object props averaged 130.37 ns before and 168.41 ns after (+29.2%), with substantial variance; one/20-key equal cases were +7.4%/+8.1% and overlapped noise. Ordinary semantic controls passed. This is comparator timing, not application throughput or bundle evidence; no performance-neutral claim is made.

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches hot-path memo prop comparison used on every memo bailout; behavior change is narrow but could slightly increase comparator cost while fixing incorrect bailouts.

Overview
Fixes memo components skipping re-renders when props swap an own key whose value matches Object.prototype (e.g. toString) for a different own key (e.g. label).

shallowEqualProps in the memo bailout path now requires the next props object to own every key from the previous props before comparing values, so inherited prototype values cannot mask a removed own prop. Comments are updated to match; the allocation-free for-in path and Object.keys fallback for non-plain objects are unchanged.

Adds an octane patch changeset and Vitest coverage (template vs value children, hydration, universal/server memo, explicit undefined vs missing keys, and prototype-name edge cases).

Reviewed by Cursor Bugbot for commit abf8059. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 23, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 23, 2026 09:23
@domgan-oai
domgan-oai merged commit b353a67 into octanejs:main Sep 23, 2026
50 checks passed
trueadm added a commit that referenced this pull request Oct 3, 2026
…d can produce (#1661)

#1279 made the plain-object memo compare check own-property membership for
every key, so an inherited Object.prototype value cannot stand in for a
removed prop. On a plain or null-prototype object a missing own prop reads as
undefined or an Object.prototype member, which is a function or an object, so
a primitive that compares equal is already own. The lookup now runs only for
undefined, function and object values.

memo-wall's wall B bails 999 rows of four primitive props and a callback on
every one_change_B; it made five lookups per row and now makes one. Paired
A/B with the #833/#1069 fixes: one_change_B 0.269 -> 0.252 ms.

memo-props gains a case for an own __proto__ prop holding Object.prototype
(the object branch; it fails without it), and memo-wall gains a deterministic
guard counting own-prop lookups per bailed row (5 on main, 1 now).

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memo skips updates when a removed own prop matches an inherited Object.prototype value

1 participant