Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/theme/DocItem/Layout/useZendesk.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ const useZendesk = () => {
script.onload = () => setIsLoaded(true);

document.body.appendChild(script);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate script elements added on each page navigation

Removing the cleanup function without adding a guard check causes duplicate Zendesk script elements to be appended to the document body on every page navigation. When the DocItemLayout component remounts after page change, the useEffect runs again and appends a new script since no check exists for whether a script with id="ze-snippet" already exists in the DOM. This can lead to multiple script loads and potential issues with the Zendesk widget.

Fix in Cursor Fix in Web

return () => {
// Check if the widget provides a specific cleanup function and call it here
if (window.zE) {
window.zE('messenger', 'hide'); // Example cleanup call, replace with actual if different
}
document.body.removeChild(script);
setIsLoaded(false);
}
}, [siteConfig.customFields.ZENDESK_KEY, siteConfig.customFields.DEVELOPMENT]);

return isLoaded;
Expand Down
Loading