Skip to content

fix: should only recycle off-screen list-item in recursive hydration#1641

Merged
gaoachao merged 3 commits intomainfrom
fix/should-recycle-onscreen-list-item-only
Sep 5, 2025
Merged

fix: should only recycle off-screen list-item in recursive hydration#1641
gaoachao merged 3 commits intomainfrom
fix/should-recycle-onscreen-list-item-only

Conversation

@gaoachao
Copy link
Copy Markdown
Collaborator

@gaoachao gaoachao commented Sep 1, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Refined hydration so only off-screen list items are considered for recycling, preventing visible items from being reused and improving reload stability.
  • Tests
    • Updated tests to assert the tightened recycling behavior during hydration.
  • Chores
    • Added a changeset for a patch release of @lynx-js/react.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Sep 1, 2025

🦋 Changeset detected

Latest commit: 7097fd6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lynx-js/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 1, 2025

📝 Walkthrough

Walkthrough

Adds a changeset for a patch to @lynx-js/react, limits recycleSignMap updates during ListChildren hydration to existing recycle entries, and updates tests to assert only off-screen list items are eligible for recycling during hydration.

Changes

Cohort / File(s) Summary
Changeset
.changeset/plenty-kiwis-live.md
Adds a patch release note: "Should only recycle off-screen list-item in recursive hydration."
Hydration logic
packages/react/runtime/src/hydrate.ts
In ListChildren hydration, guard the recycleSignMap.set(listItemID, b) with if (recycleSignMap.has(listItemID)) so signs are updated only for existing recycle entries; adds clarifying comment.
Tests
packages/react/runtime/__test__/list.test.jsx
Adjusts list.reload assertions to expect the recycle pool contains only off-screen/target list-item(s) at specific phases and that on-screen items are not recycled.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • colinaaa
  • hzy

Poem

"I hop through lists with tiny feet,
Off-screen crumbs I gently keep;
On-screen friends I never chase,
My recycle map stays in its place. 🐇✨"

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/should-recycle-onscreen-list-item-only

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Sep 1, 2025

Web Explorer

#4836 Bundle Size — 367.43KiB (0%).

7097fd6(current) vs 9e2c497 main#4829(baseline)

Bundle metrics  Change 1 change
                 Current
#4836
     Baseline
#4829
No change  Initial JS 144.23KiB 144.23KiB
No change  Initial CSS 31.84KiB 31.84KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 8 8
Change  Modules 220(+0.46%) 219
No change  Duplicate Modules 16 16
No change  Duplicate Code 3.32% 3.32%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#4836
     Baseline
#4829
No change  JS 235.43KiB 235.43KiB
No change  Other 100.16KiB 100.16KiB
No change  CSS 31.84KiB 31.84KiB

Bundle analysis reportBranch fix/should-recycle-onscreen-list...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Sep 1, 2025

React Example

#4845 Bundle Size — 237.53KiB (+0.01%).

7097fd6(current) vs 9e2c497 main#4838(baseline)

Bundle metrics  Change 1 change
                 Current
#4845
     Baseline
#4838
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 38.63% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 160 160
No change  Duplicate Modules 65 65
No change  Duplicate Code 45.83% 45.83%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#4845
     Baseline
#4838
No change  IMG 145.76KiB 145.76KiB
Regression  Other 91.77KiB (+0.03%) 91.74KiB

Bundle analysis reportBranch fix/should-recycle-onscreen-list...Project dashboard


Generated by RelativeCIDocumentationReport issue

@gaoachao gaoachao changed the title fix: should only recycle on-screen list-item in recursive hydrate fix: should only recycle off-screen list-item in recursive hydrate Sep 3, 2025
@gaoachao gaoachao force-pushed the fix/should-recycle-onscreen-list-item-only branch from 637e4c3 to 01894a5 Compare September 3, 2025 08:08
@gaoachao gaoachao requested review from DwwWxx and hzy September 3, 2025 08:08
@gaoachao gaoachao changed the title fix: should only recycle off-screen list-item in recursive hydrate fix: should only recycle off-screen list-item in recursive hydration Sep 3, 2025
Signed-off-by: BitterGourd <91231822+gaoachao@users.noreply.github.com>
@gaoachao gaoachao marked this pull request as ready for review September 3, 2025 08:10
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Sep 3, 2025

CodSpeed Performance Report

Merging #1641 will not alter performance

Comparing fix/should-recycle-onscreen-list-item-only (7097fd6) with main (9e2c497)

Summary

✅ 42 untouched benchmarks

Comment thread packages/react/runtime/__test__/list.test.jsx
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/react/runtime/__test__/list.test.jsx (3)

1777-1781: Tighten assertions: check map existence/size and avoid order dependence.

Minor: make failures crisper and resilient to insertion-order changes.

Apply this diff:

 // Should only update `list-item` in the recycling pool
 // Should not add the on-screen `list-item` to the recycling pool,
+expect(recycleSignMap).toBeInstanceOf(Map);
+expect(recycleSignMap.size).toBe(1);
-expect([...recycleSignMap.keys()]).toStrictEqual([__GetElementUniqueID(d3.__element_root)]);
+expect(new Set(recycleSignMap.keys())).toEqual(new Set([__GetElementUniqueID(d3.__element_root)]));
 expect(recycleSignMap.get(__GetElementUniqueID(d3.__element_root))).not.toBe(d3);

1948-1952: Prefer order-agnostic key checks and assert pool size.

Minor: Map key order is insertion-defined; asserting size plus Set-equality is more robust.

Apply this diff:

 // d1 was enqueued as well, so it should be in the recycling pool
-expect([...recycleSignMap.keys()]).toStrictEqual([
+expect(recycleSignMap.size).toBe(2);
+expect(new Set(recycleSignMap.keys())).toEqual(new Set([
   __GetElementUniqueID(d3.__element_root),
   __GetElementUniqueID(d1.__element_root),
-]);
+]));

1948-1952: Optional: clean up per-list recycling/sign maps at test end to avoid cross-test residue.

Not functionally necessary here, but clearing the specific list’s entries can reduce leakage when many tests run in one process.

Add near the end of this test (before the closing brace):

// Cleanup the per-list bookkeeping to avoid cross-test residue
recycleMap.clear();
delete gRecycleMap[listID];
signMap.clear();
delete gSignMap[listID];
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ec482e3 and 7097fd6.

📒 Files selected for processing (1)
  • packages/react/runtime/__test__/list.test.jsx (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1330
File: .changeset/olive-animals-attend.md:1-3
Timestamp: 2025-07-22T09:23:07.797Z
Learning: In the lynx-family/lynx-stack repository, changesets are only required for meaningful changes to end-users such as bugfixes and features. Internal/development changes like chores, refactoring, or removing debug info do not need changeset entries.
🧬 Code graph analysis (1)
packages/react/runtime/__test__/list.test.jsx (1)
packages/react/runtime/__test__/utils/nativeMethod.ts (1)
  • __GetElementUniqueID (40-43)
🔇 Additional comments (1)
packages/react/runtime/__test__/list.test.jsx (1)

1777-1781: Good: asserts constrain recycling to off-screen items (addresses prior feedback).

This directly verifies the recycling pool doesn’t absorb on-screen items during hydration and follows up on the earlier suggestion to assert recycleSignMap.

@gaoachao gaoachao requested a review from hzy September 4, 2025 08:42
@gaoachao gaoachao merged commit 80dc85e into main Sep 5, 2025
46 checks passed
@gaoachao gaoachao deleted the fix/should-recycle-onscreen-list-item-only branch September 5, 2025 06:36
colinaaa pushed a commit that referenced this pull request Sep 8, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @lynx-js/react@0.112.6

### Patch Changes

- Support nested list.
([#1581](#1581))

- Should only recycle off-screen `list-item` in recursive hydration.
([#1641](#1641))

- fix `fireEvent` type error in testing library
([#1596](#1596))

## @lynx-js/rspeedy@0.11.1

### Patch Changes

- Disable lazyCompilation by default.
([#1647](#1647))

- Bump Rsbuild v1.5.2 with Rspack v1.5.1.
([#1624](#1624))

- Add `output.dataUriLimit.*` for fine-grained control of asset
inlining. ([#1648](#1648))

    ```js
    import { defineConfig } from "@lynx-js/rspeedy";

    export default defineConfig({
      output: {
        dataUriLimit: {
          image: 5000,
          media: 0,
        },
      },
    });
    ```

## @lynx-js/tailwind-preset@0.2.1

### Patch Changes

- Extend the `uiVariants` plugin with additional states: `initial`,
`closed`, `indeterminate`, and `invalid`. These can be used with the
`ui-*` prefix (e.g., `ui-initial`, `ui-closed`, `ui-indeterminate`,
`ui-invalid`).
([#1663](#1663))

## @lynx-js/web-elements@0.8.5

### Patch Changes

- fix: register attr of width is set to height incorrectly
([#1649](#1649))

-   Updated dependencies \[]:
    -   @lynx-js/web-elements-template@0.8.5

## create-rspeedy@0.11.1



## upgrade-rspeedy@0.11.1



## @lynx-js/web-elements-template@0.8.5

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coderabbitai coderabbitai Bot mentioned this pull request Apr 10, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants