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

Modules with no header are always redrawn in updateDom, even when module content is unchanged #3440

Closed
benjaminflessner opened this issue May 1, 2024 · 5 comments
Labels

Comments

@benjaminflessner
Copy link

I found a bug in MagicMirror

Platform: Mac, Chrome

Node Version: 18

MagicMirror² Version: Latest khassel docker image

Description:
Modules with no header seems to be always refreshing, even if content did not change.

Steps to Reproduce:
Set any module to a low-update frequency, and lose the header. (Easier to see if the module calls updateDom with a visible fade)

Notice that the module refreshes every time, even if its contents do not change.

Expected Results:
Expect to see the module NOT refresh unless data changes.

Actual Results:
Module refreshes constantly!

Additional Notes:
First traced down to

headerNeedsUpdate = newHeader !== headerWrapper[0].innerHTML;

where newHeader === undefined and headerWrapper[0].innerHTML === "undefined" (the string). Looking at my page source - this is indeed correct!

<header class="module-header" style="display: none;">undefined</header>

The innerHTML is literally the string "undefined." But why?

Traced that to

moduleHeader.innerHTML = module.getHeader();
which converts the undefined return of getHeader() to the string "undefined" in innerText.

.... then I got distracted by a rabbit trail trying to figure out how the heck the following line worked at all. Shouldn't it set the style.display to none if getHeader was ==="" not !==""?

if (typeof module.getHeader() === "undefined" || module.getHeader() !== "") {

I think the only reason things work is because updateModuleContent re-sets the display style to block here:

headerWrapper[0].innerHTML = newHeader;

I'd be happy to submit a PR for this, but I'm a bit concerned I'm mis-understanding what's going on in line 41. The easy fix is to change moduleNeedsUpdate to set headerNeedsUpdate to false when newHeader === undefined && headerWrapper[0].innerHTML === "undefined". But it would be cleaner to not be sticking the string "undefined" into the DOM at all. Should probably just be setting the innerHTML to an empty string in this instance, and then handling that in moduleNeedsUpdate.

@sdetweil
Copy link
Collaborator

sdetweil commented May 2, 2024

undefined in this context means not set.

the module calling updateDom() says the content changed. it's the module's job to tell MagicMirror. we don't compare old vs new.

@sdetweil
Copy link
Collaborator

sdetweil commented May 2, 2024

in modules where I don't want the change flash, I return the same Dom object tree I built last(first) time. so the replace is identical.

the browser knows if the dom elements are different or not.

more and more the browsers are implementing a shadow Dom. memory access is significantly faster than screen drawing,
so they draw to a shadow compare and draw diffs to the screen

@benjaminflessner
Copy link
Author

the module calling updateDom() says the content changed. it's the module's job to tell MagicMirror. we don't compare old vs new.

updateDom calls updateDomWithContent which literally calls moduleNeedsUpdate whose sole purpose is to compare the header and body of the new module content with the current content to determine if an update is needed. It just doesn't work when the header is null because undefined !== "undefined".

@sdetweil
Copy link
Collaborator

sdetweil commented May 2, 2024

cool.. I am wrong.. so, edit the code and try it out.. see what happens.. all you have to do is remove 2 quotes..

you can use the developers window (ctrl-shift-i) , sources tab , to put a stop on this line of code and checkout the behavior now
i don't see any difference.. that line of code is called once at startup of module..

Copy link

github-actions bot commented Oct 5, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants