Closed chouzz closed 2 years ago
Sorry for not responding sooner. I wanted to find something sensible to say, but didn't have the time to figure it out. Did you solve the problem?
I decided to not use web woker
in vscode webview, it works good now.
Anyway, it's not a issue about d3-graphviz. Thanks your reply.
How did you avoid using the web worker? We are hitting this problem in rust-analyzer now and I am unsure how work around this.
@Veykril Just use webpack and babel compile to the js.
In the js file:
import * as d3 from 'd3';
import * as d3Graphzviz from 'd3-graphviz';
import Vue from 'vue';
Use this js file in the html. Here are webpack configuration:
target: 'web',
entry: './assets/js/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'graph.js',
libraryTarget: 'window',
},
plugins: [
new htmlWebpackPlugin({
template: 'assets/index.html',
inject: 'body',
publicPath: '#{root}/dist'
}
and let webpack and babel compile it to es2015, and it works for me in vscode webview panel.
Thanks I'll try that (though I'd hope I could get around this without the need for babel or webpack) ❤️
Edit: Looks like it just works if you disable the webworker and shared webworker option
Hi, I would like to use d3-graphviz in vscode webview, it works good. But seems once I make it as a web woker, I cannot load "@hpcc-js/wasm" successfullly.
I make some investigate and found it related
importScripts
in workerCore.js.VSCode's webview has some limit with web worker, it don't allowed to use
importScripts
.Here is the description from vscode's webview page:
fetch(workerSource) .then(result => result.blob()) .then(blob => { var blobUrl = URL.createObjectURL(blob); new Worker(blobUrl); });
export function workerCodeBody(port) {
// ----------------------- This is my changes var workerSource = event.data.vizURL fetch(workerSource) .then(result => result.blob()) .then(blob => { const blobUrl = URL.createObjectURL(blob); new Worker(blobUrl); }) // -------------------------- hpccWasm = self["@hpcc-js/wasm"]; hpccWasm.wasmFolder(event.data.vizURL.match(/.*\//)[0]); // This is an alternative workaround where wasmFolder() is not needed // document = {currentScript: {src: event.data.vizURL}}; ... }