Skip to content

Commit

Permalink
Fix for the issue #6
Browse files Browse the repository at this point in the history
* Don't use MutationObserver if running in IE
  • Loading branch information
que-etc committed Feb 16, 2017
1 parent d08f3a7 commit a8f658e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ResizeObserverController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ import isBrowser from './utils/isBrowser';
import throttle from './utils/throttle';

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

// Minimum delay before invoking the update of observers.
const REFRESH_DELAY = 20;
Expand Down
23 changes: 23 additions & 0 deletions tests/ResizeObserver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,29 @@ describe('ResizeObserver', () => {
}).then(done).catch(done.fail);
});

it('handles IE11 issue with the MutationObserver: https://jsfiddle.net/x2r3jpuz/2/', done => {
const spy = createAsyncSpy();

elements.root.insertAdjacentHTML('beforeend', `
<p>
<strong></strong>
</p>
`);

observer = new ResizeObserver(spy);
observer.observe(elements.root);

spy.nextCall().then(async () => {
const strongElemn = elements.root.querySelector('strong');

// At this step IE11 will crash if MuatationObserver is used.
strongElemn.textContent = '-';
strongElemn.textContent = '-t';

await wait(timeout);
}).then(done).catch(done.fail);
});

if (typeof document.body.style.transform !== 'undefined') {
it('doesn\'t notify of transformations', done => {
const spy = createAsyncSpy();
Expand Down

0 comments on commit a8f658e

Please sign in to comment.