Monaca Onsen UI Discord Chat Github Repo

Web Components Shadow DOM

  • Hello,

    I tried to make onsen UI running in a shadow DOM, but got an error from onsen, of “page not found” referring to templates (actually not finding templates by their Id).

    I want to check if this is possible to draw Onsen UI tree in a shadow Dom for the purpose of CSS scoping (preventing external style from linked-in and prevent application file from affecting style of the host page). By default onsen seems to be sensitive to external CSS, set outside of templates.

    If there has been some event that fire after onsen finish the entire rendering procedure this could maybe could help, since can use this event to move the UI dom into shadow. Or maybe I should do something else in order to UI to build in a Shadow DOM?


  • Onsen UI

    @Gilad-Tiram Hmm, I’ve never tried to do something like that so I’m not sure what kind of problems might appear, but perhaps you can just put the “content elements” in Shadow DOM and let the pages run normally:

      <div class="content">

    Where my-custom-shadow-content is just a custom element that creates a shadow DOM. Not sure if that’s enough for your use case, though.

    Otherwise, just use some CSS naming system like bem or a framework that applies real CSS scoping like Vue (vue-onsenui lib available).