Skip to content
Snippets Groups Projects
Commit d8b1c600 authored by Frank Bessou's avatar Frank Bessou Committed by Chris Beer
Browse files

Fix unmount not finding container when already detached from document

Closes #3533.
parent c862d2c1
Branches
No related tags found
No related merge requests found
...@@ -7,12 +7,19 @@ jest.mock('react-dom'); ...@@ -7,12 +7,19 @@ jest.mock('react-dom');
jest.mock('isomorphic-unfetch', () => jest.fn(() => Promise.resolve({ json: () => ({}) }))); jest.mock('isomorphic-unfetch', () => jest.fn(() => Promise.resolve({ json: () => ({}) })));
describe('MiradorViewer', () => { describe('MiradorViewer', () => {
let container;
let instance; let instance;
beforeAll(() => { beforeAll(() => {
container = document.createElement('div');
container.id = 'mirador';
document.body.appendChild(container);
ReactDOM.render = jest.fn(); ReactDOM.render = jest.fn();
ReactDOM.unmountComponentAtNode = jest.fn(); ReactDOM.unmountComponentAtNode = jest.fn();
instance = new MiradorViewer({ id: 'mirador' }); instance = new MiradorViewer({ id: 'mirador' });
}); });
afterAll(() => {
document.body.removeChild(container);
});
describe('constructor', () => { describe('constructor', () => {
it('returns viewer store', () => { it('returns viewer store', () => {
expect(instance.store.dispatch).toBeDefined(); expect(instance.store.dispatch).toBeDefined();
......
...@@ -19,11 +19,14 @@ class MiradorViewer { ...@@ -19,11 +19,14 @@ class MiradorViewer {
this.store = viewerConfig.store this.store = viewerConfig.store
|| createPluggableStore(this.config, this.plugins); || createPluggableStore(this.config, this.plugins);
if (config.id) {
this.container = document.getElementById(config.id);
config.id && ReactDOM.render( config.id && ReactDOM.render(
this.render(), this.render(),
document.getElementById(config.id), this.container,
); );
} }
}
/** /**
* Render the mirador viewer * Render the mirador viewer
...@@ -40,7 +43,7 @@ class MiradorViewer { ...@@ -40,7 +43,7 @@ class MiradorViewer {
* Cleanup method to unmount Mirador from the dom * Cleanup method to unmount Mirador from the dom
*/ */
unmount() { unmount() {
this.config.id && ReactDOM.unmountComponentAtNode(document.getElementById(this.config.id)); this.container && ReactDOM.unmountComponentAtNode(this.container);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment