Skip to content

[Fast Refresh] Make edits to a memo comparison function take effect - #36964

Merged
sophiebits merged 1 commit into
mainfrom
fresh-type-changes/memo-comparison
Jul 8, 2026
Merged

[Fast Refresh] Make edits to a memo comparison function take effect#36964
sophiebits merged 1 commit into
mainfrom
fresh-type-changes/memo-comparison

Conversation

@sophiebits

@sophiebits sophiebits commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Editing the second argument of memo() previously never took effect
until something else remounted the tree, for two separate reasons:

  • When adding a comparison function, we need to switch from
    SimpleMemoComponent to MemoComponent so canPreserveStateBetween
    should return false.
  • MemoComponent was missing from the hot reload type resolution in
    createWorkInProgress, so existing fibers kept reading .compare from
    the old memo object forever.

New behavior:

  • Adding or removing the comparison function remounts; we need to do
    this when adding (SimpleMemoComponent doesn't support a comparison
    function) so let's also do it when removing.
  • Editing the comparison function implementation applies in place
    with state preserved

The TODO in isCompatibleFamilyForHotReloading is removed as that
wasn't the right place to do this check.

@meta-cla meta-cla Bot added the CLA Signed label Jul 8, 2026
@github-actions github-actions Bot added the React Core Team Opened by a member of the React Core Team label Jul 8, 2026
@sophiebits
sophiebits marked this pull request as ready for review July 8, 2026 07:20
@sophiebits
sophiebits requested a review from gaearon July 8, 2026 07:20
@sophiebits
sophiebits disabled the stack merge July 8, 2026 16:11
@sophiebits
sophiebits force-pushed the fresh-type-changes/memo-comparison branch from eda886e to 2e285a1 Compare July 8, 2026 16:11
Base automatically changed from fresh-type-changes/derive-fiber-tag to main July 8, 2026 16:56
Editing the second argument of memo() previously never took effect
until something else remounted the tree, for two separate reasons:

- When adding a comparison function, we need to switch from
  SimpleMemoComponent to MemoComponent so canPreserveStateBetween
  should return false.
- MemoComponent was missing from the hot reload type resolution in
  createWorkInProgress, so existing fibers kept reading .compare from
  the old memo object forever.

New behavior:

- Adding or removing the comparison function remounts; we need to do
  this when adding (SimpleMemoComponent doesn't support a comparison
  function) so let's also do it when removing.
- Editing the comparison function implementation applies in place
  with state preserved

The TODO in isCompatibleFamilyForHotReloading is removed as that
wasn't the right place to do this check.
@sophiebits
sophiebits force-pushed the fresh-type-changes/memo-comparison branch from 2e285a1 to 2f65706 Compare July 8, 2026 16:56
@sophiebits
sophiebits requested a review from hoxyq July 8, 2026 16:56
@sophiebits
sophiebits merged commit 4400d6c into main Jul 8, 2026
181 checks passed
@react-sizebot

Copy link
Copy Markdown

Comparing: 3b9b59f...2f65706

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 7.19 kB 7.19 kB = 1.91 kB 1.91 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 614.54 kB 614.54 kB = 108.61 kB 108.61 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.19 kB 7.19 kB +0.05% 1.91 kB 1.91 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 685.73 kB 685.73 kB = 120.11 kB 120.11 kB
facebook-www/ReactDOM-prod.classic.js = 706.08 kB 706.08 kB = 123.69 kB 123.69 kB
facebook-www/ReactDOM-prod.modern.js = 696.39 kB 696.39 kB = 122.07 kB 122.07 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
facebook-www/ReactFreshRuntime-dev.classic.js +1.70% 12.57 kB 12.79 kB +1.23% 3.02 kB 3.05 kB
facebook-www/ReactFreshRuntime-dev.modern.js +1.70% 12.57 kB 12.79 kB +1.23% 3.02 kB 3.05 kB
oss-experimental/react-refresh/cjs/react-refresh-runtime.development.js +1.70% 12.59 kB 12.81 kB +1.16% 3.03 kB 3.06 kB
oss-stable-semver/react-refresh/cjs/react-refresh-runtime.development.js +1.70% 12.59 kB 12.81 kB +1.16% 3.03 kB 3.06 kB
oss-stable/react-refresh/cjs/react-refresh-runtime.development.js +1.70% 12.59 kB 12.81 kB +1.16% 3.03 kB 3.06 kB

Generated by 🚫 dangerJS against 2f65706

github-actions Bot pushed a commit that referenced this pull request Jul 8, 2026
…36964)

Editing the second argument of memo() previously never took effect
until something else remounted the tree, for two separate reasons:

- When adding a comparison function, we need to switch from
  SimpleMemoComponent to MemoComponent so canPreserveStateBetween
  should return false.
- MemoComponent was missing from the hot reload type resolution in
  createWorkInProgress, so existing fibers kept reading .compare from
  the old memo object forever.

New behavior:

- Adding or removing the comparison function remounts; we need to do
  this when adding (SimpleMemoComponent doesn't support a comparison
  function) so let's also do it when removing.
- Editing the comparison function implementation applies in place
  with state preserved

The TODO in isCompatibleFamilyForHotReloading is removed as that
wasn't the right place to do this check.

DiffTrain build for [4400d6c](4400d6c)
github-actions Bot pushed a commit that referenced this pull request Jul 8, 2026
…36964)

Editing the second argument of memo() previously never took effect
until something else remounted the tree, for two separate reasons:

- When adding a comparison function, we need to switch from
  SimpleMemoComponent to MemoComponent so canPreserveStateBetween
  should return false.
- MemoComponent was missing from the hot reload type resolution in
  createWorkInProgress, so existing fibers kept reading .compare from
  the old memo object forever.

New behavior:

- Adding or removing the comparison function remounts; we need to do
  this when adding (SimpleMemoComponent doesn't support a comparison
  function) so let's also do it when removing.
- Editing the comparison function implementation applies in place
  with state preserved

The TODO in isCompatibleFamilyForHotReloading is removed as that
wasn't the right place to do this check.

DiffTrain build for [4400d6c](4400d6c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants