Defer_load with template

I am using panel.state.onload to make the initial load more responsive. This fails to load the main component with no python error message. However the browser console shows this error coming from the bokeh.js libraries

uncaught y: could not resolve type 'maximize1', 
which could be due to a widget or a custom model not being registered before first usage

After some trial and error I discovered that if the python imports that are defined inside the function being called by the onload() are moved outside, it works!

I tried to import panel with all the extensions like tabulator, gridstack that I could think of however I could not resolve the above error until i moved the python imports to the initial script.

Is there a way to figure out which import is causing this issue?

Does defer_load work?
https://panel.holoviz.org/how_to/callbacks/defer_load.html

Also, maybe submit an issue about onload.

Thanks @ahuang11 . I discovered by trial and error that i had to include pn.extension(“codeeditor”). I guess the defer_load was not flexible enough for my use case but I will try to see if I can refactor my code to leverage it. However I believe that this would be the case for defer_load as well as essentially the javascript libraries have to be loaded before onload() is called.

Let me see if I can craft a small test case before opening an issue.

Just an update
No issue needed. I was using a custom component (full screen) without realizing it so importing it before the defer callback was what was needed as well. It works great now