[WIP] feat(ONYX-2187): fix railViewed/itemViewed tracking gaps on live home rails - #13819
[WIP] feat(ONYX-2187): fix railViewed/itemViewed tracking gaps on live home rails #13819dariakoko wants to merge 8 commits into
Conversation
| // requestAnimationFrame is mocked as `setTimeout(cb, 0)` in the RN jest environment, so the | ||
| // refresh re-check effect's measurement runs on a real (if immediate) timer tick. | ||
| const flushRaf = () => act(() => new Promise((resolve) => setTimeout(resolve, 0))) |
There was a problem hiding this comment.
This comment says the re-check runs via requestAnimationFrame, but neither HomeViewSectionSentinel nor useGridItemVisibility uses rAF — both re-check via a 1000ms setInterval poll. The flushRaf helper name and comment are misleading. Rename to reflect that it flushes the timer/microtask queue, or drop the rAF reference.
| useEffect(() => { | ||
| if (!refreshKey) { | ||
| return | ||
| } | ||
|
|
||
| trackedGridItems.clear() | ||
| }, [refreshKey, trackedGridItems]) |
There was a problem hiding this comment.
The refreshKey → trackedGridItems.clear() path is the core NWFY item_viewed re-fire fix, but it has no test. HomeViewSectionArtworksGrid.tests.tsx still only covers the once-per-id case and wasn't touched in this PR. Add a test that fires a visibility change, bumps refreshKey, then fires again and asserts item_viewed re-fires for the same artwork id.
Code ReviewSummaryFixes two tracking gaps on the live-refreshing home rails (WTYL, NWFY): I verified the core Issues Found🟡 Important — test gap on the NWFY 🟢 Suggestion — misleading test comment / helper name 🟢 Suggestion — stale PR description 🟢 Suggestion — duplicated polling logic Areas Reviewed
Note for the authorThis is a tracking/visibility change with device behavior that's hard to unit-test end to end — the PR does include before/after videos on both platforms, thanks for that. Main ask is closing the |
|
Hi there! 👋 |
This PR resolves ONYX-2187
Description
Summary
WTYL and NWFY refetch their data after user interaction (returning to Home, pull-to-refresh). Two tracking gaps existed around that refresh:
rail_viewedwasn't re-firing after a live refresh.item_viewedwasn't re-firing for NWFY grid artworks after a live refresh.Root cause for both: the shared
Sentinelcomponent's polling effect has an empty dependency array, so its visibility comparison freezes at mount — it can only ever report one true transition per mount, never again. That's invisible for its many other consumers (they only care about the first appearance), but breaks any rail that needs to re-detect "still/again on screen" after a refresh.Changes
HomeViewSectionSentinel: for live rails only (isLiveRefreshRail), replacesSentinelwith a locally-owned, ref-based visibility poll, plus an explicit re-check tied to refresh completion. Every other section (~15 types) keeps renderingSentinelunchanged.useGridItemVisibility(new hook): same fix, scoped to NWFY's grid items.GridItemVisibilitySentinel(new): same fix, scoped to NWFY's grid items.HomeViewContext.ts:removeTrackedSectionnow no-ops when there's nothing to remove, avoiding an unrelated re-render cascade across every mounted home section on each refresh.Why
useGridItemVisibilityis a hook, not a componentIt's implemented as a hook rather than a component so it doesn't add any node to the render tree — the caller attaches it directly to its existing card's own ref. A component that wraps the card in an extra View (to have something real to measure) interferes with FlashList's masonry column-height measurement and can push later grid items off screen.
It's opted into via a stable
useLiveVisibilityTrackingboolean threaded throughMasonryArtworkGridItem→MasonryInfiniteScrollArtworkGrid→GenericGrid— stable because it never changes for a given grid instance. A per-refresh counter would force FlashList's renderItem identity to change (and the whole grid to re-render/re-layout) on every refresh; a static boolean can't. The other 25+ callers of this shared grid stack never pass it and keep using Sentinel unchanged.Impressions tracking on NWFY (tracks after refresh on back, tracks after pull to refresh)
nwfy.tracking.ready.mov
Impressions tracking on WTYL (tracks after refresh on back, tracks after pull to refresh)
wtyl.tracking.ready.mov
PR Checklist
To the reviewers 👀
Changelog updates
Changelog updates
Cross-platform user-facing changes
iOS user-facing changes
Android user-facing changes
Dev changes
Need help with something? Have a look at our docs, or get in touch with us.