-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Screenshotting] Fix potential race condition when screenshotting #123820
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
Changes from all commits
d597622
c0e1bab
bdf381a
6f3a9cd
9522cd2
bf82e12
79f3af6
6ab39e8
c8583e2
4877026
73eb3c5
eb45d09
78c8506
10bebea
58d50b6
f5f8fbe
4c293fa
5b072ee
a119d82
deb0e4e
9f7eb66
b77f4cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,20 +5,28 @@ | |
| * 2.0. | ||
| */ | ||
|
|
||
| import { map as mapRecord } from 'fp-ts/lib/Record'; | ||
| import type { LayoutParams } from '../../common/layout'; | ||
| import { LayoutTypes } from '../../common'; | ||
| import type { Layout } from '.'; | ||
| import { CanvasLayout } from './canvas_layout'; | ||
| import { PreserveLayout } from './preserve_layout'; | ||
| import { PrintLayout } from './print_layout'; | ||
|
|
||
| /** | ||
| * We naively round all numeric values in the object, this will break screenshotting | ||
| * if ever a have a non-number set as a value, but this points to an issue | ||
| * in the code responsible for creating the dimensions object. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be possible to have a unit test that explores this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I think we could, but it may need to be a funcitonal test because the "break" occurs when we pass any non integer value to Chromium when launching (so floats or NaN would break it). Is that the kind of test you had in mind? |
||
| */ | ||
| const roundNumbers = mapRecord(Math.round); | ||
|
|
||
| export function createLayout({ id, dimensions, selectors, ...config }: LayoutParams): Layout { | ||
| if (dimensions && id === LayoutTypes.PRESERVE_LAYOUT) { | ||
| return new PreserveLayout(dimensions, selectors); | ||
| return new PreserveLayout(roundNumbers(dimensions), selectors); | ||
| } | ||
|
|
||
| if (dimensions && id === LayoutTypes.CANVAS) { | ||
| return new CanvasLayout(dimensions); | ||
| return new CanvasLayout(roundNumbers(dimensions)); | ||
| } | ||
|
|
||
| // layoutParams is optional as PrintLayout doesn't use it | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this can't be just:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I chose
_.defaultsis because the override behaviour is different with own props (it ignores overrides that areundefined, so we won't end up withwidth: undefinedfor ex.).Do you think we should change the type of
defaultViewportmaking bothwidthandheightrequired values? I see they are both required in theSizeobject. WDYT?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this locally, and it looks like
heightcan currently be undefined when passing it directly fromlayout.heightto thecreatePagecall resulting in this error:I think, for now, we can leave this default using the lodash algo. WDYT?