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

Disable Popover GPU acceleration on Windows. #179

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions components/popover/popover-base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ export class PopoverBase extends Component {
theme: {
backgroundColor: colors.white,
},
modifiers: {},
styleOverrides: {},
};

state = {
showPopper: this.props.isOpen || false,
popperModifiers: this.props.modifiers,
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 realize that copying props into state is almost never a good idea.
I don't expect consumers to change this modifiers prop, are we comfortable with this tradeoff, and does it need to be explicitly called out in a comment or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it not expected that consumers will change the modifiers prop? And if it's not expected to be used why is it included as a prop?

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 should clarify: I don't expect that a consumer would change the prop between renders, so we would be OK with ignoring updates to the prop and only use the initial value that is passed in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok that makes more sense. Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could avoid the problem by only putting a shouldDisableGPUAcceleration flag in state, and merging the necessary modifiers with the modifiers specified by the consumer at render time.

...Is it worth any of this complication? Should we disable it unconditionally?

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'm not opposed to disabling GPU acceleration unconditionally.
Without objection, doing that.

};

_timeout = null;
Expand All @@ -95,6 +97,20 @@ export class PopoverBase extends Component {
this.targetContainer = typeof container === 'object' ? container.current : container();
}
}

this.setState(previousState => ({
popperModifiers: {
...previousState.popperModifiers,
computeStyle: {
...previousState.popperModifiers.computeStyle,
gpuAcceleration: !(
typeof window !== `undefined` &&
window.devicePixelRatio < 1.5 &&
/Win/.test(navigator.platform)
),
},
},
}));
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -133,20 +149,19 @@ export class PopoverBase extends Component {
const {
children,
placement: popoverPlacement,
modifiers,
hideArrow,
delay,
theme,
styleOverrides,
eventsEnabled,
positionFixed,
} = this.props;
const { showPopper } = this.state;
const { showPopper, popperModifiers } = this.state;

const popover = (
<Popper
placement={popoverPlacement}
modifiers={modifiers}
modifiers={popperModifiers}
eventsEnabled={eventsEnabled}
positionFixed={positionFixed}
>
Expand Down