fix: OPTIC-765: TypeError: Cannot read properties of null (reading 'getBoundingClientRect') #6109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR fulfills these requirements
[fix|feat|ci|chore|doc]: TICKET-ID: Short description of change made
ex.fix: DEV-XXXX: Removed inconsistent code usage causing intermittent errors
Change has impacts in these area(s)
(check all that apply)
What does this fix?
The Tooltip in certain circumstances could throw an error trying to align the position of an already unmounted component which threw the error in the PR title. Added a check to ensure this does not attempt to recalculate the position of the tooltip if either the trigger or tooltip component has unmounted from the DOM during the async transition. Also I cleaned up the deps arrays to remove any stable refs from here as it is not required.
Notes to reviewers
I was not able to reproduce this in any of the Tooltip usages I was able to determine. The Sentry stack trace points directly to this function being the culprit, and given the fact we have these async functions happening within useEffects without the guard proposed in this PR, it aligns with the type of behaviour that would result in this exact error.