GoldenLayout - How can I gracefully handle an unknown component during init

357 Views Asked by At

I am working on a webapp that is served up "modules/widgets" that dynamically register themselves to GoldenLayout. The layout config is persisted and applied on startup to retain the user's window layout. Due to a number of different factors, a "module/widget" that was available to them could be removed. If that user had that "module/widget" out on their screen the last time they were logged in it is saved in the goldenlayout config. WHen the user next logs in they receive a "Configuration Error" for an "unknown component". Is there a way for GoldenLayout to just ignore unknown compoenents listed in the config?

1

There are 1 best solutions below

0
On

I will post my solution for future reference:

  • layout fails on command layout.init()
  • this is an edge case for us => happens when users disable some component via feature toggle or when test team loads and old application version that does not yet contain the component
  • we do not want to implement any complex solution to analyze layout and remove specific view but have the most robust solution => restore default layout

Here is how I solved it:

    try {
      this.layout.init();
    } catch (e) {
      console.error('Layout initialization failed', e);
      // => delete persisted layout

      // => display some toast notification that layout initialization has failed and reload/restore will happen
      setTimeout(() => location.reload(), 5000); // reload with default layout (no persisted layout present)
      return;
    }