-
Notifications
You must be signed in to change notification settings - Fork 1.4k
added parent null checks to tooltip components #8201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
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 adds null checks to tooltip components to gracefully handle cases where tooltip parent elements don't exist or have been removed from the DOM. The changes prevent potential runtime errors when tooltips attempt to interact with missing parent elements.
- Added null checks for parent elements before creating tooltips
- Added guard clauses in tooltip coordinate calculation to handle missing parents
- Added validation in the tooltip show() method to verify parent existence
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/api/tooltips/tooltipMixins.js | Added null check and DOM containment validation for parent elements before creating tooltips |
| src/api/tooltips/components/TooltipComponent.vue | Added null check in coordinate computation to return default values when parent is missing |
| src/api/tooltips/ToolTip.js | Added parent existence validation in the show() method before appending tooltip to DOM |
| package-lock.json | Contains unrelated dependency metadata changes (peer dependency flags) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/api/tooltips/ToolTip.js
Outdated
| const parentExists = this.tooltip && this.tooltip.parentElement && | ||
| document.contains(this.tooltip.parentElement); |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable this.tooltip is undefined in the Tooltip class. The code attempts to access this.tooltip.parentElement, but this.tooltip is never initialized in the constructor.
The parentElement is passed to the constructor but only provided to the Vue component, not stored as an instance variable. To fix this, you should either:
- Store
parentElementasthis.parentElementin the constructor and checkthis.parentElementdirectly, or - Store the entire options object as
this.tooltipin the constructor
Suggested fix:
constructor({ toolTipText, toolTipLocation, parentElement, cssClasses } = { ... }) {
super();
this.parentElement = parentElement; // Add this line
// ... rest of constructor
}
show() {
const parentExists = this.parentElement && document.contains(this.parentElement);
if (!parentExists) {
console.warn('Tooltip parent does not exist anymore!');
return;
}
// ... rest of method
}
src/api/tooltips/tooltipMixins.js
Outdated
| return; | ||
| } | ||
| let parentElement = this.$refs[elementRef]; | ||
| if (!parentElement || !document.contains(parentElement)) { |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method document.contains() is not a standard DOM API. To check if an element is in the document, you should use document.body.contains(parentElement) or document.documentElement.contains(parentElement) instead, which have better browser support.
Suggested fix:
if (!parentElement || !document.body.contains(parentElement)) {
console.warn('Cannot create tooltip: parent element does not exist');
return;
}| if (!parentElement || !document.contains(parentElement)) { | |
| if (!parentElement || !document.body.contains(parentElement)) { |
| inject: ['toolTipText', 'toolTipLocation', 'parentElement', 'cssClasses'], | ||
| computed: { | ||
| toolTipCoordinates() { | ||
| if (!this.parentElement || !document.contains(this.parentElement)) { |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method document.contains() is not a standard DOM API. To check if an element is in the document, you should use document.body.contains(this.parentElement) or document.documentElement.contains(this.parentElement) instead, which have better browser support.
Suggested fix:
if (!this.parentElement || !document.body.contains(this.parentElement)) {
return { top: 0, left: 0, height: 0, width: 0 };
}| if (!this.parentElement || !document.contains(this.parentElement)) { | |
| if (!this.parentElement || !document.body.contains(this.parentElement)) { |
src/api/tooltips/tooltipMixins.js
Outdated
| if (!parentElement || !document.contains(parentElement)) { | ||
| console.warn('Cannot create tooltip: parent element does not exist'); | ||
| return; | ||
| } |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new null check logic added to handle missing parent elements should be covered by tests. Consider adding test cases that verify the behavior when:
parentElementis nullparentElementis not in the document- The tooltip is created successfully with a valid parent element
This would help ensure the null checks work as expected and prevent regressions. Other API modules in the codebase have corresponding Spec files (e.g., EditorSpec.js).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!parentElement || !document.body.contains(parentElement)) { | ||
| console.warn('Cannot create tooltip: parent element does not exist'); | ||
| return; | ||
| } | ||
| if (Array.isArray(parentElement)) { | ||
| parentElement = parentElement[0]; | ||
| } |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null check should occur after handling the Array case. Currently, if parentElement is an array, document.body.contains() will be called with an array instead of an element, which may not work as expected. Consider moving the null check to after line 62 where parentElement[0] is extracted.
| if (!parentElement || !document.body.contains(parentElement)) { | |
| console.warn('Cannot create tooltip: parent element does not exist'); | |
| return; | |
| } | |
| if (Array.isArray(parentElement)) { | |
| parentElement = parentElement[0]; | |
| } | |
| if (Array.isArray(parentElement)) { | |
| parentElement = parentElement[0]; | |
| } | |
| if (!parentElement || !document.body.contains(parentElement)) { | |
| console.warn('Cannot create tooltip: parent element does not exist'); | |
| return; | |
| } |
Closes #8190
Describe your changes:
All Submissions:
Author Checklist
type:label? Note: this is not necessarily the same as the original issue.Reviewer Checklist