Skip to content

Commit 6553da8

Browse files
authored
fix: revert workers should be inline to work in other apps (#3007)
1 parent e64255a commit 6553da8

File tree

5 files changed

+26
-39
lines changed

5 files changed

+26
-39
lines changed

package-lock.json

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@
169169
"source-map-explorer": "^2.5.3",
170170
"stylelint": "^16.20.0",
171171
"ts-jest": "^29.2.5",
172-
"typescript": "^5.8.3",
173-
"workerize-loader": "^2.0.2"
172+
"typescript": "^5.8.3"
174173
},
175174
"peerDependencies": {
176175
"monaco-yql-languages": ">=1.3.0",

src/components/Graph/BlockComponents/StageBlockComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const StageBlockComponent = ({className, block}: Props) => {
1616
? block.operators.map((item) => <div key={item}>{item}</div>)
1717
: block.name}
1818
{block.tables ? (
19-
<div style={{overflow: 'hidden', textOverflow: 'ellipsis'}}>
19+
<div>
2020
<Text color="secondary">{i18n('label_tables')}: </Text>
2121
{block.tables.join(', ')}
2222
</div>

src/components/Graph/GravityGraph.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import React from 'react';
33
import {GraphState} from '@gravity-ui/graph';
44
import type {HookGraphParams} from '@gravity-ui/graph/react';
55
import {GraphBlock, GraphCanvas, useGraph, useGraphEvent} from '@gravity-ui/graph/react';
6-
// @ts-ignore - workerize-loader syntax
7-
import createWorker from 'workerize-loader!./treeLayout.worker';
86

97
import {cn} from '../../utils/cn';
108

@@ -68,21 +66,25 @@ export function GravityGraph<T>({data, theme}: Props<T>) {
6866
const {graph, start} = useGraph(config);
6967

7068
React.useEffect(() => {
71-
// Using workerize-loader to inline the worker and avoid CORS issues
72-
const worker = createWorker();
73-
74-
// Call the exported function from the worker
75-
worker
76-
.calculateLayout(data.nodes, data.links)
77-
.then((result: {layout: any; edges: any}) => {
78-
graph.setEntities({
79-
blocks: result.layout,
80-
connections: result.edges,
81-
});
82-
})
83-
.catch((err: Error) => {
84-
console.error('Worker error:', err);
69+
// Just in case, although mounting takes more time than calculation
70+
const worker = new Worker(new URL('./treeLayout', import.meta.url));
71+
worker.postMessage({
72+
nodes: data.nodes,
73+
links: data.links,
74+
});
75+
76+
worker.onmessage = function (e) {
77+
const {layout, edges} = e.data;
78+
79+
graph.setEntities({
80+
blocks: layout,
81+
connections: edges,
8582
});
83+
};
84+
85+
worker.onerror = (err) => {
86+
console.error(err);
87+
};
8688

8789
return () => {
8890
worker.terminate();

src/components/Graph/treeLayout.worker.ts renamed to src/components/Graph/treeLayout.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ function calculateTreeEdges(layoutResult: ExtendedTBlock[], connections: TConnec
359359
return connectionPaths;
360360
}
361361

362-
// Export function for workerize-loader
363-
export function calculateLayout(nodes: any[], links: any[]) {
362+
onmessage = function (e) {
363+
const {nodes, links} = e.data;
364364
const blocks = prepareBlocks(nodes);
365365
const connections = prepareConnections(links);
366366
const layout = calculateTreeLayout(blocks, connections);
367367
const edges = calculateTreeEdges(layout, connections);
368368

369-
return {
369+
postMessage({
370370
layout,
371371
edges,
372-
};
373-
}
372+
});
373+
};

0 commit comments

Comments
 (0)