Skip to content

Support for lazy loading of split bundles in pre-load scripts for Notebooks #98106

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

Closed
DonJayamanne opened this issue May 18, 2020 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@DonJayamanne
Copy link
Contributor

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

@rebornix /cc

@connor4312
Copy link
Member

@DonJayamanne what do you think of this approach? microsoft/vscode-notebook-renderer-starter@ebef3da In summary:

  1. 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)
  2. 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

@DonJayamanne
Copy link
Contributor Author

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.

Thanks again.

@connor4312
Copy link
Member

I think this should be reliable.

cc @mattbierner as the webview master

@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants