Skip to content

Commit a8f658e

Browse files
committed
Fix for the issue #6
* Don't use MutationObserver if running in IE
1 parent d08f3a7 commit a8f658e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/ResizeObserverController.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@ import isBrowser from './utils/isBrowser';
22
import throttle from './utils/throttle';
33

44
// Define whether the MutationObserver is supported.
5-
const mutationsSupported = typeof MutationObserver === 'function';
5+
// eslint-disable-next-line no-extra-parens
6+
const mutationsSupported = (
7+
typeof MutationObserver === 'function' &&
8+
// MutationObserver should not be used if running in IE11 as it's
9+
// implementation is unreliable. Example: https://jsfiddle.net/x2r3jpuz/2/
10+
// Unfortunately, there is no other way to check this issue but to use
11+
// userAgent's information.
12+
typeof navigator === 'object' &&
13+
!(
14+
navigator.appName === 'Netscape' &&
15+
navigator.userAgent.match(/Trident\/.*rv:11/)
16+
)
17+
);
618

719
// Minimum delay before invoking the update of observers.
820
const REFRESH_DELAY = 20;

tests/ResizeObserver.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,29 @@ describe('ResizeObserver', () => {
998998
}).then(done).catch(done.fail);
999999
});
10001000

1001+
it('handles IE11 issue with the MutationObserver: https://jsfiddle.net/x2r3jpuz/2/', done => {
1002+
const spy = createAsyncSpy();
1003+
1004+
elements.root.insertAdjacentHTML('beforeend', `
1005+
<p>
1006+
<strong></strong>
1007+
</p>
1008+
`);
1009+
1010+
observer = new ResizeObserver(spy);
1011+
observer.observe(elements.root);
1012+
1013+
spy.nextCall().then(async () => {
1014+
const strongElemn = elements.root.querySelector('strong');
1015+
1016+
// At this step IE11 will crash if MuatationObserver is used.
1017+
strongElemn.textContent = '-';
1018+
strongElemn.textContent = '-t';
1019+
1020+
await wait(timeout);
1021+
}).then(done).catch(done.fail);
1022+
});
1023+
10011024
if (typeof document.body.style.transform !== 'undefined') {
10021025
it('doesn\'t notify of transformations', done => {
10031026
const spy = createAsyncSpy();

0 commit comments

Comments
 (0)