Skip to content

[Components]: Fix race condition in tree reload handling#1393

Merged
MartynasStrazdas merged 6 commits into
masterfrom
mast/fix-flaky-test
Jun 9, 2026
Merged

[Components]: Fix race condition in tree reload handling#1393
MartynasStrazdas merged 6 commits into
masterfrom
mast/fix-flaky-test

Conversation

@MartynasStrazdas

@MartynasStrazdas MartynasStrazdas commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

A Flaky test (detects a change in rule condition) appeared when we switched to react 19, because of slight differences how react runs effects.

From my understanding the test fails because setting a variable trigger a reload, which produces a new modelSource React then re-runs the useEffect - removing the old listener and adding a new one. If the next variable change fires in the gap between removal and re-subscription, the event is lost and the test hangs.

Underlying issue was race condition in how tree reload is handled. It was possible for change event to be raised between listener is removed and added back. This meant that some events were missed and tree was not reloading.

@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c6d66d7

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

This PR includes changesets to release 1 package
Name Type
@itwin/presentation-components 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

@saskliutas

Copy link
Copy Markdown
Member

Looks like we need to wait for tree to actually reload (nodeLoader/modelSource) to change? d2c7082

@MartynasStrazdas

Copy link
Copy Markdown
Contributor Author

Looks like we need to wait for tree to actually reload (nodeLoader/modelSource) to change? d2c7082

Seems to fix the issue, can you push that commit here?

@saskliutas

Copy link
Copy Markdown
Member

Looks like we need to wait for tree to actually reload (nodeLoader/modelSource) to change? d2c7082

Seems to fix the issue, can you push that commit here?

Pushed

@MartynasStrazdas MartynasStrazdas marked this pull request as ready for review June 9, 2026 07:07
@MartynasStrazdas MartynasStrazdas requested a review from a team as a code owner June 9, 2026 07:07
Copilot AI review requested due to automatic review settings June 9, 2026 07:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 stabilizes the Tree update full-stack test under React 19 by ensuring assertions wait for the hook to produce a new nodeLoader before verifying the updated tree, accounting for changed effect scheduling.

Changes:

  • Track the last observed nodeLoader and wait for it to change before asserting the updated hierarchy.
  • Update the verification loop to advance the tracked nodeLoader after each successful update.

Comment thread apps/full-stack-tests/src/components/tree/Update.test.tsx Outdated
Comment thread apps/full-stack-tests/src/components/tree/Update.test.tsx Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@grigasp

grigasp commented Jun 9, 2026

Copy link
Copy Markdown
Member

A Flaky test appeared when we switched to react 19, because of slight differences how react runs effects.

Can we have more details on this?

  • which test is that
  • do we have a failure log? E.g. what exactly failed

@MartynasStrazdas MartynasStrazdas enabled auto-merge (squash) June 9, 2026 11:15
@saskliutas saskliutas changed the title [Components]: fix flaky test caused by react 19 [Components]: Fix race condition in tree reload handling Jun 9, 2026
@MartynasStrazdas MartynasStrazdas merged commit 8ee97c7 into master Jun 9, 2026
17 checks passed
@MartynasStrazdas MartynasStrazdas deleted the mast/fix-flaky-test branch June 9, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants