Skip to content

fix: reset IntersectionObserver on 0→non-zero root width transition#8184

Merged
mattcosta7 merged 2 commits into
copilot/fix-zero-size-root-racefrom
copilot/copilotfix-zero-size-root-race
Jul 17, 2026
Merged

fix: reset IntersectionObserver on 0→non-zero root width transition#8184
mattcosta7 merged 2 commits into
copilot/fix-zero-size-root-racefrom
copilot/copilotfix-zero-size-root-race

Conversation

Copilot AI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The recovery path for Safari's zero-width root race condition was a no-op. observeSubscribedElements() called observer.observe(el) on elements already being observed — which the IntersectionObserver spec defines as a no-op — so no fresh initial batch was ever delivered. Items that had collapsed during the bad zero-width batch stayed stuck as "not overflowing."

Changes

OverflowObserverProvider.tsx

  • On the 0 → non-zero root width transition, fully reset the shared IntersectionObserver before re-observing:
    observerRef.current?.disconnect()
    observerRef.current = null
    observerRootRef.current = null
    observedElementsRef.current.clear()
    observeSubscribedElements() // getObserver() now builds a fresh IO instance
    Nulling both refs forces getObserver() to construct a new IntersectionObserver, which delivers a correct initial batch for every subscribed element. No new persistent observers are introduced.

useOverflowObserver.test.tsx

  • Added disconnected: boolean tracking to MockIntersectionObserver.disconnect().
  • Strengthened the transition test: vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get') is applied before render() so the ResizeObserver effect captures lastWidth = 0 (in a real Chromium environment the <ul> has clientWidth > 0 without this). The test now explicitly asserts that the old observer was disconnected and a new instance was created — it fails against the prior no-op implementation.

Changelog

New

Changed

  • OverflowObserverProvider: on the 0→non-zero root width transition, the shared IntersectionObserver is now fully disconnected and rebuilt to guarantee a fresh observation batch.

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

The updated test verifies the contract directly: it fails if disconnect() is not called on the prior observer instance and fails if no new IntersectionObserver instance is created on the transition. The zero-width guard test and sub-pixel threshold test are unchanged and still pass.

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e74e300

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

…strengthen test assertions

Co-authored-by: mattcosta7 <8616962+mattcosta7@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix recovery path in OverflowObserverProvider fix: reset IntersectionObserver on 0→non-zero root width transition Jul 17, 2026
Copilot AI requested a review from mattcosta7 July 17, 2026 14:31
@mattcosta7
mattcosta7 marked this pull request as ready for review July 17, 2026 15:05
@mattcosta7
mattcosta7 requested a review from a team as a code owner July 17, 2026 15:06
@mattcosta7
mattcosta7 requested a review from joshblack July 17, 2026 15:06
@mattcosta7
mattcosta7 merged commit 4589f21 into copilot/fix-zero-size-root-race Jul 17, 2026
47 of 48 checks passed
@mattcosta7
mattcosta7 deleted the copilot/copilotfix-zero-size-root-race branch July 17, 2026 15:06
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. If this doesn't work, you can also use the original workflow here. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants