Skip to content

Commit 09436e8

Browse files
committed
fix: prevent race condition
1 parent 871c96d commit 09436e8

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/base/eventListeners.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* (Department of Information and Computing Sciences)
77
*/
88
import type { GraphQueryResult, MLResults, SchemaGraph, Settings } from ".";
9-
import type { ReceiveMessage, SendMessage } from "../internal";
9+
import type { ReadyMessage, ReceiveMessage, SendMessage } from "../internal";
1010

1111
/**
1212
* Performs an action every time a message of the specified type is received.
@@ -36,7 +36,13 @@ export function receiveMessage<
3636
if (data.type === typeFilter) callback(data.data as TData);
3737
}
3838

39+
const readyMessage: ReadyMessage = {
40+
data: undefined,
41+
type: `${typeFilter}Ready`
42+
};
43+
3944
windowContext.addEventListener("message", updateMessage);
45+
window.parent.postMessage(readyMessage, "*");
4046

4147
return () => windowContext.removeEventListener("message", updateMessage);
4248
}

src/internal/message.types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ export interface SchemaMessage extends BaseMessage {
6767
type: "Schema";
6868
}
6969

70+
/**
71+
* A message that notifies the frontend that the add-on wants to receive data.
72+
*
73+
* @internal
74+
*/
75+
export interface ReadyMessage extends BaseMessage {
76+
data: undefined;
77+
type: `${ReceiveMessage["type"]}Ready`;
78+
}
79+
7080
/**
7181
* A message that is sent from the frontend to request the default config. The
7282
* response should be a {@link SettingsMessage}.
@@ -95,4 +105,4 @@ export type ReceiveMessage =
95105
*
96106
* @internal
97107
*/
98-
export type SendMessage = SettingsMessage;
108+
export type SendMessage = SettingsMessage | ReadyMessage;

src/react/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function useGraphData(): GraphQueryResult | undefined {
137137
* @remarks
138138
* Component rerenders when the returned value changes.
139139
*
140-
* @returns A {@link ML} containing the results from the active machine learning
140+
* @returns A {@link MLResults} containing the results from the active machine learning
141141
* plugins.
142142
*
143143
* @category React hooks

0 commit comments

Comments
 (0)