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

Browser: Fix panel rendered waiting condition #472

Merged
merged 1 commit into from
Oct 6, 2023
Merged
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
10 changes: 5 additions & 5 deletions src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Browser {
}
}

async start(): Promise<void> {}
async start(): Promise<void> { }

validateRenderOptions(options: RenderOptions) {
if (options.url.startsWith(`socket://`)) {
Expand Down Expand Up @@ -216,7 +216,7 @@ export class Browser {
heights.dashboard.client,
scrollDivSelector
);

await new Promise(executor => setTimeout(executor, scrollDelay));
}

Expand Down Expand Up @@ -351,8 +351,8 @@ export class Browser {
return totalPanelsRendered >= panelCount;
}

const panelCount = document.querySelectorAll('.panel').length || document.querySelectorAll('.panel-container').length;
return (window as any).panelsRendered >= panelCount || (window as any).panelsRendered === undefined;
const panelCount = document.querySelectorAll('.panel-solo').length || document.querySelectorAll('[class$=\'panel-container\']').length;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did it change? Does it work right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it changes a while ago in Grafana but we didn't notice because it was 0 and panelsRendered is undefined until the panel is rendered. So for one panel (what we always render because the condition for full page is different), we checked undefined >= 0 for a while (which is false) and when the panel is rendered, we checked 0 >= 0 (which is true) so it returned.

I don't think we actually need this and we could set it to 1 but I would need to think more about it before making this more bigger change (and it would be nice to have a test suite as well for this kind of things).

return (window as any).panelsRendered >= panelCount || panelCount === 0
},
{
timeout: options.timeout * 1000,
Expand Down Expand Up @@ -533,7 +533,7 @@ export class Browser {

const loc = msg.location();
if (msgType === 'error' && msg.text() !== 'JSHandle@object') {
this.log.error('Browser console error', 'msg', msg.text(), 'url', loc.url, 'line', loc.lineNumber, 'column', loc.columnNumber);
this.log.error('Browser console error', 'msg', msg.text(), 'url', loc.url, 'line', loc.lineNumber, 'column', loc.columnNumber);
return;
}

Expand Down