-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy load of editor in module #628
Comments
If you end up following the instructions for allowing offline access, it will partially sidestep this problem. Takes me 45ms to load ngstack/code-editor locally. |
@CharlieGreenman has a pretty okay solution. It will request the JS bundle as an asset, so it happens concurrently I believe. But I wanted to lazy-load the entire dependency. So I looked at the codebase here for a bit.
However, I see the difficulty too, because if I inject the same service So this is the order that must happen:
So my solution was to call editorLoaded = (window as any).editorLoaded;
constructor(private codeEditorService: CodeEditorService) {
(window as any).editorLoaded || this.codeEditorService.loadEditor().then(() => {
(window as any).editorLoaded = this.editorLoaded = true;
});
} Then in the template I put a placeholder where the editor should be until it's loaded. This was fine, but I wanted to pre-load it too. So I made this service instead: @Injectable({ providedIn: 'root' })
export class EditorReadyService {
ready$ = new BehaviorSubject(false);
} Used it in the component like this: editorReady$ = inject(EditorReadyService).ready$; Then I re-exported it from the lazy-loaded module file. In the import('./lazy-loaded.module').then(m =>
this.injector
.get(m.CodeEditorService)
.loadEditor()
.then(() => this.injector.get(m.EditorReadyService).ready$.next(true)),
); I could access all of that here without having to load any of it up front thanks to As soon as the app is done loading, it fetches that lazy-loaded file. Pre-fetching and my app.component code both want it, so they share the request. The The only problem is I get this console error 3 times:
It never comes back and I haven't noticed anything wrong. |
cool, this is great! I'm going to dive deeper into this later on today |
For what it's worth, I ended up moving off this library and creating my own homegrown version. I found it ended up messing with the performance of the application too much |
Nice. If you end up publishing it, I might use it. For now I consider my solution technical debt |
We will think about it. In the meantime, I sent you an email if interested |
When I add CodeEditorModule.forRoot() in my app.module.ts and CodeEditorModule.forChild() in my lazyload.module.ts, the editor is loaded after startup even if the lazy load module is not.
Editor files from content delivery network should loaded only if lazy loaded modul loaded
The text was updated successfully, but these errors were encountered: