Skip to content

refactor(main): simplify _updateDom with async/await#4185

Merged
khassel merged 1 commit into
MagicMirrorOrg:developfrom
KristjanESPERANTO:refactor/updatedom
Jun 12, 2026
Merged

refactor(main): simplify _updateDom with async/await#4185
khassel merged 1 commit into
MagicMirrorOrg:developfrom
KristjanESPERANTO:refactor/updatedom

Conversation

@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

_updateDom was wrapping its entire body in a new Promise(resolve => {...}) constructor just to chain getDom() and updateDomWithContent() together. Since updateDomWithContent was already converted to async in #4182, we can now just await it directly - the manual wrapper, the explicit Promise.resolve() normalization, and the nested .then().catch() chain all become unnecessary, making the control flow easier to follow.
Also added .catch(Log.error) at both call sites, since async functions reject on error instead of swallowing it silently.

@sdetweil

Copy link
Copy Markdown
Collaborator

Cool, that was a head scratcher. Trouble caused long before await

@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator Author

I'm glad you like it. And kudos to everyone who set this up and managed to make sense of such pre-async/await patterns 🤯

@khassel khassel merged commit b9be026 into MagicMirrorOrg:develop Jun 12, 2026
12 checks passed
KristjanESPERANTO added a commit to KristjanESPERANTO/MagicMirror that referenced this pull request Jun 12, 2026
…4185)

`_updateDom` was wrapping its entire body in a `new Promise(resolve =>
{...})` constructor just to chain `getDom()` and
`updateDomWithContent()` together. Since `updateDomWithContent` was
already converted to async in MagicMirrorOrg#4182, we can now just `await` it directly
- the manual wrapper, the explicit `Promise.resolve()` normalization,
and the nested `.then().catch()` chain all become unnecessary, making
the control flow easier to follow.
Also added `.catch(Log.error)` at both call sites, since async functions
reject on error instead of swallowing it silently.
@KristjanESPERANTO KristjanESPERANTO deleted the refactor/updatedom branch June 12, 2026 22:24
KristjanESPERANTO added a commit to KristjanESPERANTO/MagicMirror that referenced this pull request Jun 12, 2026
…4185)

`_updateDom` was wrapping its entire body in a `new Promise(resolve =>
{...})` constructor just to chain `getDom()` and
`updateDomWithContent()` together. Since `updateDomWithContent` was
already converted to async in MagicMirrorOrg#4182, we can now just `await` it directly
- the manual wrapper, the explicit `Promise.resolve()` normalization,
and the nested `.then().catch()` chain all become unnecessary, making
the control flow easier to follow.
Also added `.catch(Log.error)` at both call sites, since async functions
reject on error instead of swallowing it silently.
KristjanESPERANTO added a commit to KristjanESPERANTO/MagicMirror that referenced this pull request Jun 15, 2026
…4185)

`_updateDom` was wrapping its entire body in a `new Promise(resolve =>
{...})` constructor just to chain `getDom()` and
`updateDomWithContent()` together. Since `updateDomWithContent` was
already converted to async in MagicMirrorOrg#4182, we can now just `await` it directly
- the manual wrapper, the explicit `Promise.resolve()` normalization,
and the nested `.then().catch()` chain all become unnecessary, making
the control flow easier to follow.
Also added `.catch(Log.error)` at both call sites, since async functions
reject on error instead of swallowing it silently.
khassel pushed a commit that referenced this pull request Jun 16, 2026
Follow-up to #4185. This PR replaces `.then()`/`.catch()` chains in the
DOM update flow with `async/await`, making the code easier to read and
reason about.

**What changed:**
- `createDomObjects` and `MM.updateDom` are now `async`, the nested
`.then()` callbacks are gone
- Extracted a small `createModuleDom()` helper to keep the loop in
`createDomObjects` readable
- Errors in `createDomObjects` are caught in a single `try/catch` -
before, a failing module could cause an unhandled Promise rejection
- `updateDomWithContent` now properly awaits the full show animation
before resolving. The old code called `resolve()` while the animation
was still running, which was technically wrong
- Fixed `@param {Promise} callback` in JSDoc - it's not a Promise, it's
a plain `() => void` function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants