[Dev] Teact: Debug component name on error in effect (#2463)
This commit is contained in:
parent
b1f92f4126
commit
156b0b09da
@ -571,6 +571,8 @@ function useLayoutEffectBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(`[Teact] Error in effect cleanup at cursor #${cursor} in ${componentInstance.name}`);
|
||||||
handleError(err);
|
handleError(err);
|
||||||
} finally {
|
} finally {
|
||||||
byCursor[cursor].cleanup = undefined;
|
byCursor[cursor].cleanup = undefined;
|
||||||
@ -584,24 +586,30 @@ function useLayoutEffectBase(
|
|||||||
|
|
||||||
execCleanup();
|
execCleanup();
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
try {
|
||||||
let DEBUG_startAt: number | undefined;
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
if (DEBUG) {
|
let DEBUG_startAt: number | undefined;
|
||||||
DEBUG_startAt = performance.now();
|
if (DEBUG) {
|
||||||
}
|
DEBUG_startAt = performance.now();
|
||||||
|
|
||||||
const result = effect();
|
|
||||||
if (typeof result === 'function') {
|
|
||||||
byCursor[cursor].cleanup = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG) {
|
|
||||||
const duration = performance.now() - DEBUG_startAt!;
|
|
||||||
const componentName = componentInstance.name;
|
|
||||||
if (duration > DEBUG_EFFECT_THRESHOLD) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn(`[Teact] Slow effect at cursor #${cursor}: ${componentName}, ${Math.round(duration)} ms`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = effect();
|
||||||
|
if (typeof result === 'function') {
|
||||||
|
byCursor[cursor].cleanup = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
const duration = performance.now() - DEBUG_startAt!;
|
||||||
|
const componentName = componentInstance.name;
|
||||||
|
if (duration > DEBUG_EFFECT_THRESHOLD) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn(`[Teact] Slow effect at cursor #${cursor}: ${componentName}, ${Math.round(duration)} ms`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(`[Teact] Error in effect at cursor #${cursor} in ${componentInstance.name}`);
|
||||||
|
handleError(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user