Skip to content

Conversation

@PupilTong
Copy link
Collaborator

@PupilTong PupilTong commented Aug 15, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved exposure monitoring to ensure appear/disappear events fire correctly when elements enter or leave view, preventing spurious “disappear” behavior and keeping UI states consistent.
  • Tests

    • Added end-to-end coverage validating exposure events, confirming correct background color changes for control and target elements.
  • Chores

    • Declared a patch release for @lynx-js/web-core. No source or public API changes.

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

changeset-bot bot commented Aug 15, 2025

🦋 Changeset detected

Latest commit: 8e7d5e4

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

This PR includes changesets to release 7 packages
Name Type
@lynx-js/web-core Patch
@lynx-js/web-core-server Patch
@lynx-js/web-constants Patch
@lynx-js/web-mainthread-apis Patch
@lynx-js/web-worker-rpc Patch
@lynx-js/web-worker-runtime Patch
@lynx-js/web-style-transformer 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 Aug 15, 2025

📝 Walkthrough

Walkthrough

Introduces a fix in createExposureMonitor to dispatch disexposure when a previously exposed element stops intersecting, adds a new Playwright test and React test page validating no fake disappear, and includes a changeset declaring a patch release for @lynx-js/web-core. No public APIs change.

Changes

Cohort / File(s) Summary of changes
Release metadata
./.changeset/modern-wombats-float.md
Adds changeset for a patch release: “fix: fake uidisappear event.” No source changes.
Exposure monitor logic
packages/web-platform/web-core/src/uiThread/crossThreadHandlers/createExposureMonitor.ts
Adds else-if branch to handle non-intersecting previously exposed elements: dispatch disexposure and remove from exposedElements. No API/signature changes.
Web tests
packages/web-platform/web-tests/tests/react.spec.ts, packages/web-platform/web-tests/tests/react/api-exposure-no-fake-disappear/index.jsx
Adds Playwright spec asserting green backgrounds (no fake disappear) and a React test page wiring uiappear/uidisappear to state for validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Sherry-hue
  • colinaaa
  • Huxpro

Poem

A bunny peeks with watchful care 🐇
“Exposed, then gone?” — we fix the snare.
No phantom fades, no fake goodbye,
Green fields persist beneath the sky. 🌿
With tests aligned and carrots near,
We ship a patch—now all is clear! ✅

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

codecov bot commented Aug 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 15, 2025

CodSpeed Performance Report

Merging #1539 will not alter performance

Comparing PupilTong:p/hw/fix-exposure-fake-disappear (8e7d5e4) with main (31f3175)

Summary

✅ 10 untouched benchmarks

@relativeci
Copy link

relativeci bot commented Aug 15, 2025

React Example

#4363 Bundle Size — 237.04KiB (0%).

8e7d5e4(current) vs 31f3175 main#4360(baseline)

Bundle metrics  no changes
                 Current
#4363
     Baseline
#4360
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 158 158
No change  Duplicate Modules 64 64
No change  Duplicate Code 45.86% 45.86%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#4363
     Baseline
#4360
No change  IMG 145.76KiB 145.76KiB
No change  Other 91.28KiB 91.28KiB

Bundle analysis reportBranch PupilTong:p/hw/fix-exposure-fake...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link

relativeci bot commented Aug 15, 2025

Web Explorer

#4356 Bundle Size — 366.68KiB (~+0.01%).

8e7d5e4(current) vs 31f3175 main#4353(baseline)

Bundle metrics  Change 3 changes Regression 1 regression
                 Current
#4356
     Baseline
#4353
Regression  Initial JS 143.49KiB(~+0.01%) 143.48KiB
No change  Initial CSS 31.84KiB 31.84KiB
Change  Cache Invalidation 39.13% 0%
No change  Chunks 7 7
No change  Assets 7 7
Change  Modules 212(+0.95%) 210
No change  Duplicate Modules 17 17
No change  Duplicate Code 3.89% 3.89%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#4356
     Baseline
#4353
Regression  JS 234.68KiB (~+0.01%) 234.66KiB
No change  Other 100.16KiB 100.16KiB
No change  CSS 31.84KiB 31.84KiB

Bundle analysis reportBranch PupilTong:p/hw/fix-exposure-fake...Project dashboard


Generated by RelativeCIDocumentationReport issue

@PupilTong PupilTong force-pushed the p/hw/fix-exposure-fake-disappear branch from 695b05c to 0fb51d8 Compare August 19, 2025 10:18
@PupilTong PupilTong changed the title WIP: fix fake disappear event fix: fix fake disappear event Aug 19, 2025
@PupilTong PupilTong marked this pull request as ready for review August 19, 2025 10:19
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 a bug in the exposure monitoring system where fake uidisappear events were being triggered when elements became visible. The fix ensures that disappear events are only sent when elements actually transition from visible to not visible.

Key Changes

  • Fixed logic in the Intersection Observer to prevent fake disappear events
  • Added a test case to verify the fix works correctly
  • Updated changeset documentation

Reviewed Changes

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

File Description
packages/web-platform/web-core/src/uiThread/crossThreadHandlers/createExposureMonitor.ts Fixed the condition to only send disappear events when elements actually disappear
packages/web-platform/web-tests/tests/react/api-exposure-no-fake-disappear/index.jsx Added test component to verify the fix
packages/web-platform/web-tests/tests/react.spec.ts Added test case for the fix
.changeset/modern-wombats-float.md Added changeset documentation

Copy link
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 (4)
.changeset/modern-wombats-float.md (1)

5-5: Polish the changeset description for clarity.

The current phrasing is terse and slightly ungrammatical. Consider a clearer, release-note-friendly message.

Apply this diff:

-fix: fake uidisappear event
+fix: prevent false uidisappear/disexposure events
packages/web-platform/web-tests/tests/react.spec.ts (1)

971-985: Solid regression test; consider a slightly longer stabilization wait to reduce flakiness.

The assertions correctly validate that neither uiappear nor uidisappear was spuriously fired for #target. To make the test more resilient across CI environments where IO/paint scheduling varies, bump the wait a bit.

-          await wait(300);
+          await wait(500);
packages/web-platform/web-core/src/uiThread/crossThreadHandlers/createExposureMonitor.ts (1)

56-68: Optional: Base exposure state on intersectionRatio vs. isIntersecting to honor exposure-area thresholds.

Using isIntersecting alone does not reflect configured exposure-area thresholds. When threshold > 0, entries fire on threshold crossings even while isIntersecting stays true; in that case, we won’t send disexposure when the ratio drops below threshold but remains > 0.

A simple refinement is to track the per-target threshold and compare intersectionRatio to that threshold.

Apply this diff to the callback:

-  const intersectionObserverCallback = (
-    entries: IntersectionObserverEntry[],
-  ) => {
-    entries.forEach(({ target, isIntersecting }) => {
-      if (isIntersecting && !exposedElements.has(target)) {
-        sendExposureEvent(target, true, target.getAttribute('exposure-id'));
-        exposedElements.add(target);
-      } else if (!isIntersecting && exposedElements.has(target)) {
-        sendExposureEvent(target, false, target.getAttribute('exposure-id'));
-        exposedElements.delete(target);
-      }
-    });
-  };
+  const intersectionObserverCallback = (
+    entries: IntersectionObserverEntry[],
+  ) => {
+    entries.forEach(({ target, intersectionRatio }) => {
+      const threshold = thresholds.get(target) ?? 0;
+      const above = intersectionRatio >= threshold;
+      if (above && !exposedElements.has(target)) {
+        sendExposureEvent(target, true, target.getAttribute('exposure-id'));
+        exposedElements.add(target);
+      } else if (!above && exposedElements.has(target)) {
+        sendExposureEvent(target, false, target.getAttribute('exposure-id'));
+        exposedElements.delete(target);
+      }
+    });
+  };

And add the following supportive changes elsewhere:

// near other WeakMaps
const thresholds = new WeakMap<Element, number>();
// inside startIntersectionObserver, after computing `threshold`
thresholds.set(target, threshold);

This preserves current behavior for threshold=0 and makes exposure/disexposure align with the configured exposure-area.

packages/web-platform/web-tests/tests/react/api-exposure-no-fake-disappear/index.jsx (1)

31-36: Naming nit: variable suggests only “disappear” but is set on both appear and disappear.

For readability, consider renaming uidisappearTriggered to something like exposureEventTriggered (or anyExposureTriggered), since both binduidisappear and binduiappear set it to true.

-  const [uidisappearTriggered, setUidisappearTriggered] = useState(false);
+  const [exposureEventTriggered, setExposureEventTriggered] = useState(false);
...
-          background: uidisappearTriggered ? 'red' : 'green',
+          background: exposureEventTriggered ? 'red' : 'green',
...
-        binduidisappear={() => {
-          setUidisappearTriggered(true);
+        binduidisappear={() => {
+          setExposureEventTriggered(true);
         }}
-        binduiappear={() => {
-          setUidisappearTriggered(true);
+        binduiappear={() => {
+          setExposureEventTriggered(true);
         }}
📜 Review details

Configuration used: .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 31f3175 and 8e7d5e4.

📒 Files selected for processing (4)
  • .changeset/modern-wombats-float.md (1 hunks)
  • packages/web-platform/web-core/src/uiThread/crossThreadHandlers/createExposureMonitor.ts (1 hunks)
  • packages/web-platform/web-tests/tests/react.spec.ts (1 hunks)
  • packages/web-platform/web-tests/tests/react/api-exposure-no-fake-disappear/index.jsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-07-22T09:23:07.797Z
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.

Applied to files:

  • .changeset/modern-wombats-float.md
📚 Learning: 2025-07-22T09:26:16.722Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1330
File: .changeset/olive-animals-attend.md:1-3
Timestamp: 2025-07-22T09:26:16.722Z
Learning: In the lynx-family/lynx-stack repository, CI checks require changesets when files matching the pattern "src/**" are modified (as configured in .changeset/config.json). For internal changes that don't need meaningful changesets, an empty changeset file is used to satisfy the CI requirement while not generating any release notes.

Applied to files:

  • .changeset/modern-wombats-float.md
🪛 LanguageTool
.changeset/modern-wombats-float.md

[grammar] ~5-~5: There might be a mistake here.
Context: ...: patch --- fix: fake uidisappear event

(QB_NEW_EN)

🔇 Additional comments (2)
.changeset/modern-wombats-float.md (1)

2-3: Changeset scope looks correct.

Targeting a patch for @lynx-js/web-core aligns with the bugfix nature and matches the code changes under src/. No public API change indicated.

packages/web-platform/web-core/src/uiThread/crossThreadHandlers/createExposureMonitor.ts (1)

63-66: Correctly dispatch disexposure when an exposed element stops intersecting.

This fixes the false disappear by ensuring disexposure/uidisappear only fires for elements that were actually exposed. The set bookkeeping is sound.

@PupilTong PupilTong merged commit 6acb2d9 into lynx-family:main Aug 19, 2025
69 of 72 checks passed
colinaaa pushed a commit that referenced this pull request Aug 26, 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/[email protected]

### Patch Changes

- fix `withInitDataInState` got wrong state in 2nd or more times
`defaultDataProcessor`, now it will keep its own state.
([#1478](#1478))

- change `__CreateElement('raw-text')` to `__CreateRawText('')` to avoid
`setNativeProps` not working
([#1570](#1570))

- Fix wrong render result when using expression as `key`.
([#1541](#1541))

See
[#1371](#1371)
for more details.

- fix: `Cannot read properties of undefined` error when using `Suspense`
([#1569](#1569))

- Add `animate` API in Main Thread Script(MTS), so you can now control a
CSS animation imperatively
([#1534](#1534))

    ```ts
    import type { MainThread } from "@lynx-js/types";

    function startAnimation(ele: MainThread.Element) {
      "main thread";
      const animation = ele.animate([{ opacity: 0 }, { opacity: 1 }], {
        duration: 3000,
      });

      // Can also be paused
      // animation.pause()
    }
    ```

## @lynx-js/[email protected]

### Patch Changes

- Support caching Lynx native events when chunk splitting is enabled.
([#1370](#1370))

When `performance.chunkSplit.strategy` is not `all-in-one`, Lynx native
events are cached until the BTS chunk is fully loaded and are replayed
when that chunk is ready. The `firstScreenSyncTiming` flag will no
longer change to `jsReady` anymore.

- Support exporting `Promise` and function in `lynx.config.ts`.
([#1590](#1590))

- Fix missing `publicPath` using when `rspeedy dev --mode production`.
([#1310](#1310))

- Updated dependencies
\[[`aaca8f9`](aaca8f9)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## [email protected]

### Patch Changes

- Add `@lynx-js/preact-devtools` by default.
([#1593](#1593))

## @lynx-js/[email protected]

### Patch Changes

- Bump @clack/prompts to v1.0.0-alpha.4
([#1559](#1559))

## @lynx-js/[email protected]

### Patch Changes

- Support using multiple times in different environments.
([#1498](#1498))

- Support caching Lynx native events when chunk splitting is enabled.
([#1370](#1370))

When `performance.chunkSplit.strategy` is not `all-in-one`, Lynx native
events are cached until the BTS chunk is fully loaded and are replayed
when that chunk is ready. The `firstScreenSyncTiming` flag will no
longer change to `jsReady` anymore.

- Updated dependencies
\[[`f0d483c`](f0d483c),
[`e4d116b`](e4d116b),
[`d33c1d2`](d33c1d2)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Support using multiple times in different environments.
([#1498](#1498))

- Alias `@lynx-js/preact-devtools` to `false` to reduce an import of
empty webpack module.
([#1593](#1593))

## @lynx-js/[email protected]

### Patch Changes

- Support `lynx.createSelectorQuery().select()` and `setNativeProps` API
([#1570](#1570))

## @lynx-js/[email protected]

### Patch Changes

- fix: globalThis is never accessible in MTS
([#1531](#1531))

-   Updated dependencies \[]:
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- fix: fake uidisappear event
([#1539](#1539))

- Updated dependencies
\[[`70863fb`](70863fb)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- fix: globalThis is never accessible in MTS
([#1531](#1531))

- Updated dependencies
\[[`70863fb`](70863fb)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- fix: globalThis is never accessible in MTS
([#1531](#1531))

- Updated dependencies
\[[`70863fb`](70863fb)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Add new `LynxCacheEventsPlugin`, which will cache Lynx native events
until the BTS chunk is fully loaded, and replay them when the BTS chunk
is ready. ([#1370](#1370))

- Updated dependencies
\[[`aaca8f9`](aaca8f9)]:
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Updated dependencies
\[[`aaca8f9`](aaca8f9)]:
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Updated dependencies
\[[`aaca8f9`](aaca8f9)]:
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Updated dependencies
\[[`aaca8f9`](aaca8f9)]:
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Always inline the background script that contains rspack runtime
module. ([#1582](#1582))

- Updated dependencies
\[[`aaca8f9`](aaca8f9)]:
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Add `lynxCacheEventsSetupList` and `lynxCacheEvents` to
RuntimeGlobals. It will be used to cache Lynx native events until the
BTS chunk is fully loaded, and replay them when the BTS chunk is ready.
([#1370](#1370))

## [email protected]



## @lynx-js/[email protected]



## @lynx-js/[email protected]



## @lynx-js/[email protected]

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

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants