Skip to content

fix: should clear list callbacks when __DestroyLifetime#2112

Merged
gaoachao merged 4 commits intomainfrom
fix/update-list-callbacks
Jan 29, 2026
Merged

fix: should clear list callbacks when __DestroyLifetime#2112
gaoachao merged 4 commits intomainfrom
fix/update-list-callbacks

Conversation

@gaoachao
Copy link
Copy Markdown
Collaborator

@gaoachao gaoachao commented Jan 15, 2026

Summary by CodeRabbit

  • New Features

    • Exposed a lightweight native event accessor for testing and integration.
  • Bug Fixes

    • Fixed a memory leak by clearing list update callbacks when a list is destroyed.
  • Tests

    • Added tests to verify list callbacks are cleared on destruction.
  • Chores

    • Prepared a patch release entry for the package.

✏️ Tip: You can customize this high-level summary in your review settings.

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

@gaoachao gaoachao requested review from HuJean and hzy as code owners January 15, 2026 08:59
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: a34e7fb

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 Jan 15, 2026

📝 Walkthrough

Walkthrough

Adds a native __DestroyLifetime listener to clear list callbacks on destruction, updates the __UpdateListCallbacks type to accept nullable callbacks, introduces tests and a test-native shim, and adds a changeset for a patch release of @lynx-js/react.

Changes

Cohort / File(s) Summary
Runtime list cleanup
packages/react/runtime/src/snapshot/list.ts
Register native __DestroyLifetime listener that calls __UpdateListCallbacks(list, null, null, null) to clear list callbacks when a lifetime is destroyed.
Type declaration updates
packages/react/runtime/types/types.d.ts
Change __UpdateListCallbacks signature so componentAtIndex, enqueueComponent, and componentAtIndexes may be `
Tests & test shim
packages/react/runtime/__test__/list.test.jsx, packages/react/runtime/__test__/utils/globals.js
Add test verifying callbacks are cleared after __DestroyLifetime dispatch; introduce/extend a test-native shim with event listener API and a _clear reset helper.
Testing environment API
packages/testing-library/testing-environment/src/index.ts
Expose lynx.getNative() returning a lightweight native object with event listener management and messaging stubs for tests.
Release metadata
.changeset/tender-radios-lose.md
Add a changeset indicating a patch release for @lynx-js/react documenting the memory-leak fix.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • HuJean
  • hzy

Poem

🐇 I hop through lists and hush the call,
When DestroyLifetime rings, I clear them all.
Callbacks tucked, no memory stew,
A nimble burrow, fresh and new. 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: clearing list callbacks when the __DestroyLifetime event is triggered, which matches the core implementation across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 15, 2026

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
4715 1 4714 127
View the top 2 failed test(s) by shortest run time
packages/rspeedy/plugin-qrcode/test/shortcuts.test.ts > PluginQRCode - CLI Shortcuts > open page
Stack Traces | 1.51s run time
Error: Matcher did not succeed in time.
 ❯ test/shortcuts.test.ts:51:40

Caused by: Caused by: Caused by: AssertionError: expected "Vt" to be called 2 times, but got 0 times
tests/reactlynx.spec.ts::reactlynx3 tests › basic › basic-reload-page-only-one
Stack Traces | 13.1s run time
reactlynx.spec.ts:90:5 basic-reload-page-only-one

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jan 15, 2026

CodSpeed Performance Report

Merging this PR will improve performance by 9.45%

Comparing fix/update-list-callbacks (a34e7fb) with main (556fe9f)

Summary

⚡ 1 improved benchmark
✅ 62 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
basic-performance-div-100 7.6 ms 6.9 ms +9.45%

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Jan 15, 2026

Web Explorer

#7434 Bundle Size — 383.63KiB (+0.02%).

a34e7fb(current) vs d1b0d9e main#7429(baseline)

Bundle metrics  Change 3 changes Improvement 1 improvement
                 Current
#7434
     Baseline
#7429
Improvement  Initial JS 154.03KiB(-0.45%) 154.71KiB
No change  Initial CSS 35.05KiB 35.05KiB
Change  Cache Invalidation 84.88% 0%
No change  Chunks 8 8
No change  Assets 8 8
Change  Modules 239(+0.84%) 237
No change  Duplicate Modules 16 16
No change  Duplicate Code 2.99% 2.99%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#7434
     Baseline
#7429
Improvement  JS 251.56KiB (-0.44%) 252.66KiB
Regression  Other 97.02KiB (+1.22%) 95.85KiB
No change  CSS 35.05KiB 35.05KiB

Bundle analysis reportBranch fix/update-list-callbacksProject dashboard


Generated by RelativeCIDocumentationReport issue

Comment thread packages/react/runtime/src/snapshot/list.ts Outdated
Copy link
Copy Markdown
Collaborator

@hzy hzy left a comment

Choose a reason for hiding this comment

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

You will need a test to avoid regress of this leak

@gaoachao
Copy link
Copy Markdown
Collaborator Author

@HuJean @hzy PTAL~

@gaoachao gaoachao requested review from HuJean and hzy January 21, 2026 12:47
@gaoachao gaoachao merged commit d1b0d9e into main Jan 29, 2026
106 of 111 checks passed
@gaoachao gaoachao deleted the fix/update-list-callbacks branch January 29, 2026 10:03
colinaaa pushed a commit that referenced this pull request Feb 1, 2026
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/motion@0.0.2

### Patch Changes

- Add initial support for `@lynx-js/motion`
([#1062](#1062))

## @lynx-js/react@0.116.2

### Patch Changes

- Fix "TypeError: not a function" error caused by `replaceAll` not
supported in ES5.
([#2142](#2142))

- Bump `swc_core` v56.
([#2154](#2154))

- Use `disableDeprecatedWarning` option to suppress BROKEN warnings
during compilation.
([#2157](#2157))

1. BROKEN: `getNodeRef`/`getNodeRefFromRoot`/`createSelectorQuery` on
component instance is broken and MUST be migrated in ReactLynx 3.0,
please use ref or lynx.createSelectorQuery instead.
2. BROKEN: `getElementById` on component instance is broken and MUST be
migrated in ReactLynx 3.0, please use ref or lynx.getElementById
instead.

- Fix memory leak by clearing list callbacks when \_\_DestroyLifetime
event is triggered.
([#2112](#2112))

## @lynx-js/rspeedy@0.13.3

### Patch Changes

-   Updated dependencies \[]:
    -   @lynx-js/web-rsbuild-server-middleware@0.19.7

## @lynx-js/qrcode-rsbuild-plugin@0.4.4

### Patch Changes

- Bump `@clack/prompts` v1.0
([#2171](#2171))

## @lynx-js/react-rsbuild-plugin@0.12.7

### Patch Changes

- Updated dependencies
\[[`92881e7`](92881e7),
[`1a5f2a1`](1a5f2a1)]:
    -   @lynx-js/template-webpack-plugin@0.10.3
    -   @lynx-js/css-extract-webpack-plugin@0.7.0
    -   @lynx-js/react-webpack-plugin@0.7.3
    -   @lynx-js/react-alias-rsbuild-plugin@0.12.7
    -   @lynx-js/use-sync-external-store@1.5.0
    -   @lynx-js/react-refresh-webpack-plugin@0.3.4

## @lynx-js/web-constants@0.19.7

### Patch Changes

-   Updated dependencies \[]:
    -   @lynx-js/web-worker-rpc@0.19.7

## @lynx-js/web-core@0.19.7

### Patch Changes

- feat: add browser config of lynx-view, now you can customize the
browser config of lynx-view:
([#2140](#2140))

        lynxView.browserConfig = {
          pixelRatio: 1,
          pixelWidth: 1234,
          pixelHeight: 5678,
        }

-   Updated dependencies \[]:
    -   @lynx-js/web-constants@0.19.7
    -   @lynx-js/web-mainthread-apis@0.19.7
    -   @lynx-js/web-worker-rpc@0.19.7
    -   @lynx-js/web-worker-runtime@0.19.7

## @lynx-js/web-core-wasm@0.0.2

### Patch Changes

- Updated dependencies
\[[`43fc7e7`](43fc7e7)]:
    -   @lynx-js/web-elements@0.11.1
    -   @lynx-js/web-worker-rpc@0.19.7

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

### Patch Changes

- feat: add wheel event handling and corresponding tests for
x-foldview-ng
([#2145](#2145))

## @lynx-js/web-mainthread-apis@0.19.7

### Patch Changes

-   Updated dependencies \[]:
    -   @lynx-js/web-constants@0.19.7

## @lynx-js/web-worker-runtime@0.19.7

### Patch Changes

-   Updated dependencies \[]:
    -   @lynx-js/web-constants@0.19.7
    -   @lynx-js/web-mainthread-apis@0.19.7
    -   @lynx-js/web-worker-rpc@0.19.7

## @lynx-js/template-webpack-plugin@0.10.3

### Patch Changes

- Fix "Failed to load CSS update file" for lazy bundle
([#2150](#2150))

- Fix "TypeError: cannot read property 'call' of undefined" error of
lazy bundle HMR.
([#2146](#2146))

## create-rspeedy@0.13.3



## @lynx-js/react-alias-rsbuild-plugin@0.12.7



## upgrade-rspeedy@0.13.3



## @lynx-js/web-core-server@0.19.7



## @lynx-js/web-rsbuild-server-middleware@0.19.7



## @lynx-js/web-worker-rpc@0.19.7

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants