Skip to content

Commit

Permalink
Bulk vue updates on update (#4235)
Browse files Browse the repository at this point in the history
I noticed that adding or changing a large number of elements, especially
inside an SVG tag, takes very long.

This changes the update handler to first load all dependencies in
parallel and then update the elements.
  • Loading branch information
NiklasNeugebauer authored Jan 20, 2025
1 parent ca5e9bd commit 4990c72
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nicegui/static/nicegui.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,17 @@ function createApp(elements, options) {
document.getElementById("popup").ariaHidden = false;
},
update: async (msg) => {
const loadPromises = Object.entries(msg)
.filter(([_, element]) => element && (element.component || element.libraries))
.map(([_, element]) => loadDependencies(element, options.prefix, options.version));

await Promise.all(loadPromises);

for (const [id, element] of Object.entries(msg)) {
if (element === null) {
delete this.elements[id];
continue;
}
if (element.component || element.libraries) {
await loadDependencies(element, options.prefix, options.version);
}
this.elements[id] = element;
replaceUndefinedAttributes(this.elements, id);
}
Expand Down

0 comments on commit 4990c72

Please sign in to comment.