Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] runtime: log if willStart takes more than 3s #1633

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/lifecycle_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function wrapError(fn: (...args: any[]) => any, hookName: string) {
new Promise((resolve) => setTimeout(() => resolve(TIMEOUT), 3000)),
]).then((res) => {
if (res === TIMEOUT && node.fiber === fiber && node.status <= 2) {
console.warn(timeoutError);
console.log(timeoutError);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions tests/components/__snapshots__/lifecycle.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ exports[`lifecycle hooks sub widget (inside sub node): hooks are correctly calle
}"
`;

exports[`lifecycle hooks timeout in onWillStart doesn't emit a warning if app is destroyed 1`] = `
exports[`lifecycle hooks timeout in onWillStart doesn't emit a console log if app is destroyed 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -696,7 +696,7 @@ exports[`lifecycle hooks timeout in onWillStart doesn't emit a warning if app is
}"
`;

exports[`lifecycle hooks timeout in onWillStart emits a warning 1`] = `
exports[`lifecycle hooks timeout in onWillStart emits a console log 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -709,7 +709,7 @@ exports[`lifecycle hooks timeout in onWillStart emits a warning 1`] = `
}"
`;

exports[`lifecycle hooks timeout in onWillUpdateProps emits a warning 1`] = `
exports[`lifecycle hooks timeout in onWillUpdateProps emits a console log 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -723,7 +723,7 @@ exports[`lifecycle hooks timeout in onWillUpdateProps emits a warning 1`] = `
}"
`;

exports[`lifecycle hooks timeout in onWillUpdateProps emits a warning 2`] = `
exports[`lifecycle hooks timeout in onWillUpdateProps emits a console log 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down
38 changes: 19 additions & 19 deletions tests/components/lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ describe("lifecycle hooks", () => {
await mount(Test, fixture);
});

test("timeout in onWillStart emits a warning", async () => {
const { warn } = console;
let warnArgs: any[];
console.warn = jest.fn((...args) => (warnArgs = args));
test("timeout in onWillStart emits a console log", async () => {
const { log } = console;
let logArgs: any[];
console.log = jest.fn((...args) => (logArgs = args));
const { setTimeout } = window;
let timeoutCbs: any = {};
let timeoutId = 0;
Expand All @@ -138,17 +138,17 @@ describe("lifecycle hooks", () => {
}
await nextMicroTick();
await nextMicroTick();
expect(console.warn).toHaveBeenCalledTimes(1);
expect(warnArgs![0]!.message).toBe("onWillStart's promise hasn't resolved after 3 seconds");
expect(console.log).toHaveBeenCalledTimes(1);
expect(logArgs![0]!.message).toBe("onWillStart's promise hasn't resolved after 3 seconds");
} finally {
console.warn = warn;
console.log = log;
window.setTimeout = setTimeout;
}
});

test("timeout in onWillStart doesn't emit a warning if app is destroyed", async () => {
const { warn } = console;
console.warn = jest.fn();
test("timeout in onWillStart doesn't emit a console log if app is destroyed", async () => {
const { log } = console;
console.log = jest.fn();
const { setTimeout } = window;
let timeoutCbs: any = {};
let timeoutId = 0;
Expand All @@ -172,14 +172,14 @@ describe("lifecycle hooks", () => {
}
await nextMicroTick();
await nextMicroTick();
expect(console.warn).toHaveBeenCalledTimes(0);
expect(console.log).toHaveBeenCalledTimes(0);
} finally {
console.warn = warn;
console.log = log;
window.setTimeout = setTimeout;
}
});

test("timeout in onWillUpdateProps emits a warning", async () => {
test("timeout in onWillUpdateProps emits a console log", async () => {
class Child extends Component {
static template = xml``;
setup() {
Expand All @@ -193,9 +193,9 @@ describe("lifecycle hooks", () => {
}
const parent = await mount(Parent, fixture, { test: true });

const { warn } = console;
let warnArgs: any[];
console.warn = jest.fn((...args) => (warnArgs = args));
const { log } = console;
let logArgs: any[];
console.log = jest.fn((...args) => (logArgs = args));
const { setTimeout } = window;
let timeoutCbs: any = {};
let timeoutId = 0;
Expand All @@ -218,12 +218,12 @@ describe("lifecycle hooks", () => {
delete timeoutCbs[id];
}
await tick;
expect(console.warn).toHaveBeenCalledTimes(1);
expect(warnArgs![0]!.message).toBe(
expect(console.log).toHaveBeenCalledTimes(1);
expect(logArgs![0]!.message).toBe(
"onWillUpdateProps's promise hasn't resolved after 3 seconds"
);
} finally {
console.warn = warn;
console.log = log;
window.setTimeout = setTimeout;
}
});
Expand Down
Loading