You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Preloading scripts works as expected in output renderes. However if the preload script is a bundle that lazyloads other bundle scripts, then this doesn't work.
The reason this doesn't work is because WebPack will attempt to load the resource dynamically. However this can only be done if resources are using the vscode-resource scheme (which cannot be hardcoded).
Current approach in Python webiview notebook implementation
We make use of __webpack_public_path__ variable, this is initialized to a global variable window.__PVSC_Public_Path
In our webivew we initialize the above value as follows: window.__PVSC_Public_Path = "${webView.asWebviewUri(Uri.file(<Extension dir/xyz>)).toString()}/";
This option will not work with preload scripts for notebooks
At the moment the only solution I can see is to dynamically generate a JS file with the above code in it
Ensure the above JS file is preloaded first
Again, this might not work well
Output renderers do not have access to asWebViewUri method, hence any attempt to generate this value based on active Notebook Editor is not guaranteed to work.
We (extension authors) cannot assume this value is a constant across all webviews
In the webpack config, record the relative path from the entrypoint filename to the output directory. (Not dealing with any extra fancy multi-entrypoint configs right now)
When the entrypoint loads, form and set the __webpack_public_path__ based on the url of the current script + the relative path we previously recorded
That works, that's pretty much what I'm doing today. As long as we have VSCodes blessing for such a solution I'm happy. Didn't want to make any assumptions about how the scripts are loaded and the like.
Closing as this issue.
Preloading scripts works as expected in output renderes. However if the preload script is a bundle that lazyloads other bundle scripts, then this doesn't work.
The reason this doesn't work is because WebPack will attempt to load the resource dynamically. However this can only be done if resources are using the
vscode-resource
scheme (which cannot be hardcoded).Current approach in Python webiview notebook implementation
__webpack_public_path__
variable, this is initialized to a global variablewindow.__PVSC_Public_Path
window.__PVSC_Public_Path = "${webView.asWebviewUri(Uri.file(<Extension dir/xyz>)).toString()}/";
This option will not work with preload scripts for notebooks
Again, this might not work well
asWebViewUri
method, hence any attempt to generate this value based on active Notebook Editor is not guaranteed to work.@rebornix /cc
The text was updated successfully, but these errors were encountered: