Skip to content

Commit d8b37bb

Browse files
committed
[fix] fixed lifecycle issue
1 parent 57ee357 commit d8b37bb

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/content/core/defineFeature/loadFeat.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ type Feature = {paths: Array<string>, name: string, feat: any | unknown};
77

88
let features: Array<Feature> = [];
99

10+
let prepared = false;
1011
function prepare() {
12+
if (prepared) return;
13+
prepared = true;
1114
for (const feat of getAllFeatures()) {
1215
const instance = new feat.cl();
1316
features.push({
@@ -35,9 +38,9 @@ async function initFeatures() {
3538
}
3639

3740
promises.push((async () => {
38-
try {
39-
const startTime = performance.now();
41+
const startTime = performance.now();
4042

43+
try {
4144
const p = featureData.feat.init(normalizedPath); // initialise it
4245
if (p && typeof p.then === 'function')
4346
await p; // if the initialiser is async, await it
@@ -46,7 +49,7 @@ async function initFeatures() {
4649

4750
debugVerbose(`[loadFeat] initFeatures: ${featureData.name}: Initialised in ${(endTime - startTime).toFixed(1)}ms`);
4851
} catch (e) {
49-
console.error(`[loadFeat] initFeatures: ${featureData.name}: Failed to initialise`, e);
52+
console.error(`[loadFeat] initFeatures: ${featureData.name}: Failed to initialise after ${((performance.now() - startTime) * 1000).toFixed(3)}s`, e);
5053
}
5154

5255
// Install hooks
@@ -60,9 +63,11 @@ async function initFeatures() {
6063
switch (document.readyState) {
6164
case "interactive":
6265
featureData.feat.onDOMLoaded();
66+
break;
6367
case "complete":
6468
featureData.feat.onDOMLoaded();
6569
featureData.feat.onPageLoaded();
70+
break;
6671
}
6772
})());
6873
}

0 commit comments

Comments
 (0)