antvis/G6

layout failed Error: Failed to execute 'postMessage' on 'Worker' #4893

loveshiun posted onGitHub

Describe the bug

layout failed Error: Failed to execute 'postMessage' on 'Worker': function (e) {
    obj[action](e);

  } could not be cloned.

    at LayoutController.runWebworker (https://4dmzm8.csb.app/node_modules/@antv/g6-pc/es/graph/controller/layout.js:432:14)

    at eval (https://4dmzm8.csb.app/node_modules/@antv/g6-pc/es/graph/controller/layout.js:397:22)

Your Example Website or App

https://codesandbox.io/s/cocky-euler-4dmzm8?file=/index.js

Steps to Reproduce the Bug or Issue

  1. Try to comment out the 3 lines after console.log("try to update the graph"); (line: 182 in the example link)

     graph.data(newData);
     graph.render();
     graph.updateItem(graph.getNodes()[0], config);

    the graph works as expected.

  2. Add back the 3 lines, the graph will not update.

  3. Keep the 3 lines, but change workerEnabled from true to false, the graph will update normally again.

  4. Set workerEnabled to true again, but now add one more line graph.render(); after the 3 lines, the graph will also update.

Besides, when workerEnabled is true, some operations may result in layout failed Error: Failed to execute 'postMessage' on 'Worker'.

Expected behavior

When workerEnabled: true, should have nearly the same behavior as workerEnabled: false?

Screenshots or Videos

No response

Platform

  • OS: Linux
  • Browser: Chrome (incognito)
  • Version:

Additional context

No response

The example app is updated from https://codesandbox.io/s/0vg0cl


call updateItem in the listener of afterlayout, and the listener should be bound before changeData or render called, like:

// 'once' for responsing afterlayout once, and 'on' for every time graph.once('afterlayout', e => { graph.updateItem(graph.getNodes()[0], config); }) graph.changeData(newData);

posted by Yanyan-Wang over 1 year ago

@Yanyan-Wang Thank you! 😊

posted by loveshiun over 1 year ago

Fund this Issue

$0.00
Funded

Pull requests