Skip to content

Conversation

@hzy
Copy link
Collaborator

@hzy hzy commented Jul 16, 2025

Summary

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Summary by CodeRabbit

  • Bug Fixes
    • Improved synchronization between list items when their item-key changes, ensuring consistent behavior across components.
  • Documentation
    • Updated documentation to clarify how changes to item-key are handled and to illustrate expected behavior with examples.

Copilot AI review requested due to automatic review settings July 16, 2025 13:24
@changeset-bot
Copy link

changeset-bot bot commented Jul 16, 2025

🦋 Changeset detected

Latest commit: 7b6eb7a

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
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

This change updates the logic for handling attribute changes in list items within the @lynx-js/react package, specifically addressing synchronization issues when the item-key changes but the React key remains the same. It refines type usage, adjusts control flow for attribute updates, clarifies documentation regarding this behavior, and extends tests to verify the new handling of item-key changes.

Changes

File(s) Change Summary
.changeset/shaky-swans-end.md Adds a patch note explaining the synchronization issue and the new behavior for item-key changes.
packages/react/runtime/src/listUpdateInfo.ts Updates onSetAttribute method: changes parameter types to PlatformInfo, revises logic for handling differing item-key values, and updates method signatures.
packages/react/runtime/src/snapshot/platformInfo.ts Narrows the type of oldValue to PlatformInfo in a method call to onSetAttribute.
packages/react/runtime/src/snapshot/spread.ts Defers initialization of oldValue, improves handling of potentially undefined values, and optimizes logic for extracting oldPlatformInfo.
packages/react/runtime/test/list.test.jsx Extends the "update-list-info" should work when setAttribute test with assertions verifying insert and remove actions when item-key changes.

Sequence Diagram(s)

sequenceDiagram
    participant ReactLynx
    participant ListUpdateInfoRecording
    participant LynxEngine

    ReactLynx->>ListUpdateInfoRecording: onSetAttribute(child, attr, oldAttr)
    alt oldAttr missing or attr["item-key"] == oldAttr["item-key"]
        ListUpdateInfoRecording->>ListUpdateInfoRecording: Update platformInfoUpdate map
    else attr["item-key"] != oldAttr["item-key"]
        ListUpdateInfoRecording->>ListUpdateInfoRecording: Call onInsertBefore(child, nextSibling)
        ListUpdateInfoRecording->>LynxEngine: Schedule removal and insertion
    end
Loading

Suggested labels

platform:Web

Poem

A bunny hopped through lists one day,
Noticed keys that went astray.
When item-key would change its tune,
Yet React’s key stayed far too soon,
Now with this patch, the lists align—
Synchrony restored, all items fine!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 ERROR  Cannot resolve version $@rspack/core in overrides. The direct dependencies don't have dependency "@rspack/core".
For help, run: pnpm help install


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 835cc64 and 7b6eb7a.

📒 Files selected for processing (2)
  • .changeset/shaky-swans-end.md (1 hunks)
  • packages/react/runtime/__test__/list.test.jsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/shaky-swans-end.md
🔇 Additional comments (1)
packages/react/runtime/__test__/list.test.jsx (1)

378-421: Excellent test coverage for item-key change behavior.

The new test assertions properly verify that changing the item-key attribute triggers remove and insert operations instead of simple updates. The test structure is well-organized with clear separation between different scenarios, and the snapshot assertions accurately validate the expected behavior where insertAction and removeAction are populated while updateAction remains empty.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where React list items with changed item-key attributes were not being properly removed and reinserted. The fix ensures that when a list item's item-key changes (even if the React key stays the same), the item is treated as a removal and insertion operation rather than an update, which aligns with the Lynx Engine's expectations.

  • Modified list update logic to detect item-key changes and trigger remove/insert operations
  • Updated type signatures to use proper PlatformInfo types instead of any
  • Fixed null handling in platform info extraction to prevent errors when oldValue is undefined

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/react/runtime/src/snapshot/spread.ts Fixed null handling for oldValue and reordered assignment for proper platform info extraction
packages/react/runtime/src/snapshot/platformInfo.ts Added type cast to ensure oldValue is treated as PlatformInfo
packages/react/runtime/src/listUpdateInfo.ts Enhanced onSetAttribute to detect item-key changes and trigger remove/insert operations
.changeset/shaky-swans-end.md Added changelog entry documenting the fix

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 16, 2025

CodSpeed Performance Report

Merging #1299 will not alter performance

Comparing hzy:p/hzy/remove-insert-when-item-key-changed (7b6eb7a) with main (ec7228f)

Summary

✅ 10 untouched benchmarks

@relativeci
Copy link

relativeci bot commented Jul 16, 2025

React Example

#3083 Bundle Size — 234.49KiB (+0.02%).

7b6eb7a(current) vs ec7228f main#3063(baseline)

Bundle metrics  Change 1 change
                 Current
#3083
     Baseline
#3063
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 37.83% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 157 157
No change  Duplicate Modules 63 63
No change  Duplicate Code 45.88% 45.88%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#3083
     Baseline
#3063
No change  IMG 145.76KiB 145.76KiB
Regression  Other 88.73KiB (+0.06%) 88.68KiB

Bundle analysis reportBranch hzy:p/hzy/remove-insert-when-ite...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link

relativeci bot commented Jul 16, 2025

Web Explorer

#3073 Bundle Size — 304.59KiB (0%).

7b6eb7a(current) vs ec7228f main#3054(baseline)

Bundle metrics  Change 1 change
                 Current
#3073
     Baseline
#3054
No change  Initial JS 140.65KiB 140.65KiB
No change  Initial CSS 31.83KiB 31.83KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 4 4
No change  Assets 5 5
Change  Modules 205(+0.49%) 204
No change  Duplicate Modules 17 17
No change  Duplicate Code 4.22% 4.22%
No change  Packages 3 3
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#3073
     Baseline
#3054
No change  JS 221.88KiB 221.88KiB
No change  Other 50.89KiB 50.89KiB
No change  CSS 31.83KiB 31.83KiB

Bundle analysis reportBranch hzy:p/hzy/remove-insert-when-ite...Project dashboard


Generated by RelativeCIDocumentationReport issue

@hzy hzy force-pushed the p/hzy/remove-insert-when-item-key-changed branch from 0eabade to 835cc64 Compare July 18, 2025 07:34
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Zhiyuan Hong <[email protected]>
@hzy hzy force-pushed the p/hzy/remove-insert-when-item-key-changed branch from 835cc64 to 7b6eb7a Compare July 18, 2025 09:09
@hzy hzy enabled auto-merge July 18, 2025 10:12
@hzy hzy added this pull request to the merge queue Jul 21, 2025
Merged via the queue into lynx-family:main with commit 19c7f91 Jul 21, 2025
44 checks passed
@hzy hzy deleted the p/hzy/remove-insert-when-item-key-changed branch July 21, 2025 14:17
github-merge-queue bot pushed a commit that referenced this pull request Jul 28, 2025
…ave been changed" (#1353)

Reverts #1299

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Simplified internal handling of attribute updates for list items,
streamlining how changes to item attributes are processed.
* Improved logic for managing old attribute values, ensuring more
consistent and predictable updates.

* **Tests**
* Removed specific test cases related to list item attribute changes to
align with updated logic.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Aug 21, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants