Bpmn-viewer construction

Constructing a bpmn-viewer (**const my_viewer = new BpmnJS({container: #my_container});**) requires the id. of its container in the DOM. Apparently (logically?), the DOM must have finished loading. So the pre-condition of constructing a bpmn-viewer is: console.assert(window.document.readyState !== 'loading');.
Is it really true? I mean that the bpmn-viewer may record “my_container” without accessing, for example as follows: window.document.getElementById(my_container);?
In short, is it reliable to have **const my_viewer = new BpmnJS({container: #my_container});** without knowing if the DOM has finished loading?
Thanks.

When you create a viewer, the DOM node you want to add the viewer to has to exist. In most cases, this means that the DOM has to be loaded.
You can use window.addEventListener('DOMContentLoaded') to create the viewer after everything has finished loading.

In short, is it reliable to have const my_viewer = new BpmnJS({container: #my_container}); without knowing if the DOM has finished loading?

Not when working with IDs. You can instead pass a DOM node directly and not use the CSS selector.

Thanks Martin. Very clear. It was my initial assumption, but I just expected a confirmation. Regards

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.