ocLazyLoad icon indicating copy to clipboard operation
ocLazyLoad copied to clipboard

AngularJS: Broken lazy loaded modules on state removal

Open realph opened this issue 7 years ago • 1 comments

I'm using ocLazyLoad in combination with UI-Router to lazy load my modules on state transition.

const state = {
  name: 'home.**',
  url: '/home',
  lazyLoad = transition => {
    transition
      .injector()
      .get('$ocLazyLoad')
      .inject('home-module.ts');
  };
}

$stateRegistry.register(state);

This works great. I'm able to visit that state which lazy loads home-module.ts, which in turn registers the components that are a part of home-module.ts. This all works as expected.

I then want the ability to de-register that very state, and reregister the same state.

$stateRegistry.deregister(state);
$stateRegistry.register(state);

If I now revisit the home.** state the module is not lazy loaded and its components aren't registered. I'm trying to understand what's going on here.

I have a feeling that when we deregister the state, something happens to that lazy loaded module - it's not unloaded because we cannot do that in JS. I'm guessing that the namespace (the module name) creates a pointer that references the original state name (home.**) and when we deregister the state, that pointer is broken. I'm out of ideas at this point.

Any help on this would be appreciated. Thanks in advance!

realph avatar May 09 '18 15:05 realph

If you don't mind me asking, what's the use case for deregistering a state at runtime? That's something I've never actually seen done in the wild and I'd like to know more.

vort3xxx avatar Sep 24 '18 13:09 vort3xxx