Skip to content

Conversation

@hzy
Copy link
Collaborator

@hzy hzy commented Jul 18, 2025

Summary

Checklist

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

Summary by CodeRabbit

  • Bug Fixes

    • Prevented unexpected attribute operations when passing undefined as a prop in JSX elements.
  • New Features

    • Added a test to ensure no unnecessary patch is emitted when hydrating elements with undefined props.
  • Refactor

    • Updated the serialization format for snapshot values from arrays to objects with string keys to improve consistency.
  • Tests

    • Adjusted existing test snapshots to reflect the new serialization format for values.
    • Added coverage for scenarios involving undefined and null props during hydration.

Copilot AI review requested due to automatic review settings July 18, 2025 09:48
@changeset-bot
Copy link

changeset-bot bot commented Jul 18, 2025

🦋 Changeset detected

Latest commit: a96b7de

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 18, 2025

Walkthrough

The changes update the serialization format of the values property in snapshot data from arrays to objects with string indices, affecting type declarations, serialization logic, and test snapshots. Additional test coverage is introduced to verify no patches are emitted for undefined attributes in hydration scenarios.

Changes

Files/Group Change Summary
.changeset/calm-lies-dig.md Added a changeset documenting a patch for handling undefined attributes in JSX for @lynx-js/react.
packages/react/runtime/src/snapshot.ts Changed values type from array to object in SerializedSnapshotInstance; updated serialization logic.
packages/react/runtime/test/lifecycle/reload.test.jsx Updated test snapshots: values fields now objects with string keys instead of arrays.
packages/react/runtime/test/snapshot/event.test.jsx
packages/react/runtime/test/snapshot/ref.test.jsx
Updated test snapshots: values now objects with string keys instead of arrays in event/ref tests.
packages/react/runtime/test/preact.test.jsx Added test to ensure no patch is emitted when hydrating with undefined raw-text prop.
packages/react/testing-library/src/tests/act.test.jsx Updated test snapshots: values fields changed from arrays to objects with string keys.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant SnapshotInstance
    participant SerializedSnapshot

    TestSuite->>SnapshotInstance: Call toJSON()
    SnapshotInstance->>SnapshotInstance: Convert __values array to object with string keys
    SnapshotInstance-->>SerializedSnapshot: Return object with values as Record<string, unknown>
    SerializedSnapshot-->>TestSuite: Used in test snapshot comparison
Loading

Suggested labels

platform:Web

Poem

In the meadow of code, a change takes root,
Arrays to objects—snapshots now astute!
No more patches for undefined in sight,
Hydration’s calm, all tests pass bright.
With stringy keys and bunny glee,
Serialization hops ahead, as happy as can be! 🐇

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 a96b7de and 124a125.

📒 Files selected for processing (7)
  • .changeset/calm-lies-dig.md (1 hunks)
  • packages/react/runtime/__test__/lifecycle/reload.test.jsx (6 hunks)
  • packages/react/runtime/__test__/preact.test.jsx (1 hunks)
  • packages/react/runtime/__test__/snapshot/event.test.jsx (2 hunks)
  • packages/react/runtime/__test__/snapshot/ref.test.jsx (3 hunks)
  • packages/react/runtime/src/snapshot.ts (2 hunks)
  • packages/react/testing-library/src/__tests__/act.test.jsx (2 hunks)
✅ Files skipped from review due to trivial changes (3)
  • packages/react/testing-library/src/tests/act.test.jsx
  • packages/react/runtime/test/snapshot/event.test.jsx
  • packages/react/runtime/test/snapshot/ref.test.jsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/react/runtime/test/preact.test.jsx
  • packages/react/runtime/src/snapshot.ts
  • packages/react/runtime/test/lifecycle/reload.test.jsx
  • .changeset/calm-lies-dig.md
✨ 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 undefined attribute values in React components were causing unexpected __SetAttribute operations during serialization. The change modifies how snapshot values are serialized by converting arrays to objects, which ensures undefined values are preserved during JSON serialization and prevents unnecessary attribute operations.

Key changes:

  • Changed values type from any[] to Record<string, unknown> in SerializedSnapshotInstance interface
  • Modified serialization logic to convert array values to objects using Object.assign
  • Added test case to verify undefined values don't cause patches

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react/runtime/src/snapshot.ts Updates type definition and serialization logic to convert array values to objects
packages/react/runtime/test/snapshot/ref.test.jsx Updates test expectations to reflect new object-based values format
packages/react/runtime/test/snapshot/event.test.jsx Updates test expectations to reflect new object-based values format
packages/react/runtime/test/preact.test.jsx Adds new test case for undefined attribute handling
packages/react/runtime/test/lifecycle/reload.test.jsx Updates test expectations to reflect new object-based values format
.changeset/calm-lies-dig.md Documents the fix for undefined attribute handling

@hzy hzy force-pushed the p/hzy/perf-0718 branch from 42b7527 to a96b7de Compare July 18, 2025 09:55
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 18, 2025

CodSpeed Performance Report

Merging #1311 will not alter performance

Comparing hzy:p/hzy/perf-0718 (124a125) with main (ec7228f)

Summary

✅ 10 untouched benchmarks

@hzy hzy force-pushed the p/hzy/perf-0718 branch from a96b7de to 124a125 Compare July 18, 2025 10:13
@relativeci
Copy link

relativeci bot commented Jul 18, 2025

React Example

#3093 Bundle Size — 234.46KiB (~+0.01%).

124a125(current) vs ec7228f main#3063(baseline)

Bundle metrics  Change 1 change
                 Current
#3093
     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
#3093
     Baseline
#3063
No change  IMG 145.76KiB 145.76KiB
Regression  Other 88.7KiB (+0.02%) 88.68KiB

Bundle analysis reportBranch hzy:p/hzy/perf-0718Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link

relativeci bot commented Jul 18, 2025

Web Explorer

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

124a125(current) vs ec7228f main#3054(baseline)

Bundle metrics  Change 1 change
                 Current
#3083
     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
#3083
     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/perf-0718Project dashboard


Generated by RelativeCIDocumentationReport issue

@colinaaa colinaaa enabled auto-merge July 18, 2025 11:00
@colinaaa colinaaa added this pull request to the merge queue Jul 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 18, 2025
@colinaaa colinaaa added this pull request to the merge queue Jul 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 18, 2025
@colinaaa colinaaa added this pull request to the merge queue Jul 18, 2025
Merged via the queue into lynx-family:main with commit f242de8 Jul 18, 2025
44 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Jul 18, 2025
…bute value is `undefined`" (#1317)

Reverts #1311, as it causes the performance of
`JSON.stringify(__root)` to degrade by about ~10%.

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

## Summary by CodeRabbit

* **Bug Fixes**
* Improved handling of undefined attribute values to prevent unintended
behavior in intrinsic elements.

* **Refactor**
* Updated the serialization format of snapshot data, changing the
representation of values from objects with numeric keys to arrays for
improved consistency.

* **Tests**
* Modified multiple test snapshots to reflect the new array-based format
for values.
  * Removed a test case related to patch emission for undefined values.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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