From 00a7289e53b707f2e8ed1200a592bb3e61597e66 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Sun, 11 Aug 2019 16:13:47 +0200 Subject: [PATCH] Fix IE11 regressions (#1856) * Fix IE11 not resetting style properties * Fix "new Event" not supported in IE11 --- src/diff/props.js | 2 +- test-utils/test/shared/act.test.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/diff/props.js b/src/diff/props.js index 41484bf155..15352ed5a5 100644 --- a/src/diff/props.js +++ b/src/diff/props.js @@ -31,7 +31,7 @@ function setStyle(style, key, value) { style.setProperty(key, value); } else { - style[key] = typeof value==='number' && IS_NON_DIMENSIONAL.test(key)===false ? value+'px' : value || null; + style[key] = typeof value==='number' && IS_NON_DIMENSIONAL.test(key)===false ? value+'px' : value || ''; } } diff --git a/test-utils/test/shared/act.test.js b/test-utils/test/shared/act.test.js index f1d3750e9b..3dce5aa769 100644 --- a/test-utils/test/shared/act.test.js +++ b/test-utils/test/shared/act.test.js @@ -4,6 +4,15 @@ import { useEffect, useState } from 'preact/hooks'; import { setupScratch, teardown } from '../../../test/_util/helpers'; import { act } from '../../src'; +// IE11 doesn't support `new Event()` +function createEvent(name) { + if (typeof Event === 'function') return new Event(name); + + const event = document.createEvent('Event'); + event.initEvent(name, true, true); + return event; +} + /** @jsx h */ describe('act', () => { @@ -156,13 +165,13 @@ describe('act', () => { // Click button. This will schedule an update which is deferred, as is // normal for Preact, since it happens outside an `act` call. - button.dispatchEvent(new Event('click')); + button.dispatchEvent(createEvent('click')); expect(button.textContent).to.equal('0'); act(() => { // Click button a second time. This will schedule a second update. - button.dispatchEvent(new Event('click')); + button.dispatchEvent(createEvent('click')); }); // All state updates should be applied synchronously after the `act` // callback has run but before `act` returns.