Skip to content

Commit

Permalink
fix: Improve performance on lower end devices
Browse files Browse the repository at this point in the history
  • Loading branch information
devknoll committed Oct 19, 2022
1 parent 179b236 commit 48dfef8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,15 @@ export function initializePolyfill(updateCallback: () => void) {

instance = {
connect() {
for (const child of node.childNodes) {
for (
let child = node.firstChild;
child != null;
child = child.nextSibling
) {
// Ensure all children are created and connected first.
getOrCreateInstance(child);
}
innerController.connected();
scheduleUpdate();
},

disconnect() {
Expand All @@ -445,7 +448,11 @@ export function initializePolyfill(updateCallback: () => void) {
inlineStyles.removeProperty(CUSTOM_UNIT_VARIABLE_CQW);
inlineStyles.removeProperty(CUSTOM_UNIT_VARIABLE_CQH);
}
for (const child of node.childNodes) {
for (
let child = node.firstChild;
child != null;
child = child.nextSibling
) {
const instance = getInstance(child);
instance?.disconnect();
}
Expand Down Expand Up @@ -515,7 +522,11 @@ export function initializePolyfill(updateCallback: () => void) {
innerController.updated();
}

for (const child of node.childNodes) {
for (
let child = node.firstChild;
child != null;
child = child.nextSibling
) {
getOrCreateInstance(child).update(currentState);
}
},
Expand All @@ -526,7 +537,11 @@ export function initializePolyfill(updateCallback: () => void) {

mutate() {
cacheKey = Symbol();
for (const child of node.childNodes) {
for (
let child = node.firstChild;
child != null;
child = child.nextSibling
) {
getOrCreateInstance(child).mutate();
}
},
Expand All @@ -541,6 +556,7 @@ export function initializePolyfill(updateCallback: () => void) {

documentElement.prepend(globalStyleElement, dummyElement);
getOrCreateInstance(documentElement);
scheduleUpdate();
}

class NodeController<T extends Node> {
Expand Down
1 change: 1 addition & 0 deletions tests/wpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ function createLocalServer(): Promise<Local> {
server.start(
{
key: process.env.BROWSERSTACK_ACCESS_KEY,
verbose: true,
},
err => {
if (err) {
Expand Down

0 comments on commit 48dfef8

Please sign in to comment.