Fix crash in React 18 StrictMode (#1680)

This commit is contained in:
Xiaoji Chen 2022-01-10 20:01:07 -08:00 committed by Xiaoji Chen
parent 9a729c211a
commit d7ebfbc2cd

View File

@ -317,12 +317,20 @@ export default class Mapbox {
// This eliminates the timing issue between calling resize() and DOM update
/* eslint-disable accessor-pairs */
const {container} = props;
Object.defineProperty(container, 'offsetWidth', {get: () => this.width});
Object.defineProperty(container, 'clientWidth', {get: () => this.width});
Object.defineProperty(container, 'offsetWidth', {
configurable: true,
get: () => this.width
});
Object.defineProperty(container, 'clientWidth', {
configurable: true,
get: () => this.width
});
Object.defineProperty(container, 'offsetHeight', {
configurable: true,
get: () => this.height
});
Object.defineProperty(container, 'clientHeight', {
configurable: true,
get: () => this.height
});