Skip to content
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

[FIX][16.0] web_refresher: error when dom destroyed during timeout #3086

Merged
merged 1 commit into from
Feb 10, 2025
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
27 changes: 14 additions & 13 deletions web_refresher/static/src/js/refresher.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ export function useRefreshAnimation(timeout) {
const refreshClass = "o_content__refresh";
let timeoutId = null;

/**
* @returns {DOMTokenList|null}
*/
function contentClassList() {
const content = document.querySelector(".o_content");
return content ? content.classList : null;
}

function clearAnimationTimeout() {
if (timeoutId) {
clearTimeout(timeoutId);
Expand All @@ -29,11 +21,20 @@ export function useRefreshAnimation(timeout) {

function animate() {
clearAnimationTimeout();
contentClassList().add(refreshClass);
timeoutId = setTimeout(() => {
contentClassList().remove(refreshClass);
clearAnimationTimeout();
}, timeout);
const content = document.querySelector(".o_content");
if (content) {
content.classList.add(refreshClass);
timeoutId = setTimeout(() => {
// Check if element still exists in DOM after timeout
if (
document.contains(content) &&
content.classList.contains(refreshClass)
) {
content.classList.remove(refreshClass);
}
clearAnimationTimeout();
}, timeout);
}
}

return animate;
Expand Down