Skip to content

fix(datetime): prevent hidden-state observer from tearing down ready class on initial entry#31108

Open
ShaneK wants to merge 1 commit intomainfrom
FW-7284
Open

fix(datetime): prevent hidden-state observer from tearing down ready class on initial entry#31108
ShaneK wants to merge 1 commit intomainfrom
FW-7284

Conversation

@ShaneK
Copy link
Copy Markdown
Member

@ShaneK ShaneK commented Apr 30, 2026

Issue number: internal


What is the current behavior?

ion-datetime runs two IntersectionObservers: one to detect when the host becomes visible (which adds datetime-ready) and one to detect when it becomes hidden (which removes the class and tears down listeners). When the host mounts offscreen, both observers receive an initial "not intersecting" entry on observe(). The hidden-state observer treats that initial entry as a real visible-to-hidden transition, queues a writeTask to remove datetime-ready, and races the layout-based fallback (ensureReadyIfVisible) that adds the class after 100ms. On WebKit the remove wins often enough that the e2e test for the fallback (added in #30793 to fix #30706) had to be skipped on Mobile Safari. Anything in production that adds datetime-ready outside of a real isIntersecting: true event is exposed to the same race.

What is the new behavior?

A hasBeenIntersecting flag is set true only when visibleCallback observes isIntersecting: true. The hidden-state observer's teardown is gated on this flag, so the synthetic initial "not intersecting" entry is ignored. The flag is reset when the host actually transitions to hidden and on disconnectedCallback. The previously duplicated init-listeners + ready-class block is consolidated into a single markReady helper. The WebKit skip on the IO-fallback e2e test has been removed.

Does this introduce a breaking change?

  • Yes
  • No

Other information

The asymmetry where ensureReadyIfVisible (the layout fallback) deliberately does NOT set hasBeenIntersecting is load-bearing: the flag must reflect a real observer signal, not a fallback-driven write, otherwise the bug returns. This is called out at the guard site so future cleanups don't undo it.

This test was most likely to fail in docker testing Linux Webkit with --repeat-each=20 because it was pretty flaky. I was able to force it to fail under these conditions and, after fixing it, it no longer failed.

Relevant Preview Link:

@ShaneK ShaneK requested a review from a team as a code owner April 30, 2026 19:51
@ShaneK ShaneK requested a review from thetaPC April 30, 2026 19:51
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment Apr 30, 2026 7:52pm

Request Review

@github-actions github-actions Bot added the package: core @ionic/core package label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: IonDateTime sometimes show invisible calendar

1 participant