Add cleanup function to registering the message listener
This cleanup function would never be called in normal operation, but if we do decide to add a dependency to this `useEffect`, this will ensure that only one listener is registered at a time.
This commit is contained in:
@@ -65,7 +65,7 @@ export function VariantAnalysis({
|
||||
const [repoResults, setRepoResults] = useState<VariantAnalysisScannedRepositoryResult[]>(initialRepoResults);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('message', (evt: MessageEvent) => {
|
||||
const listener = (evt: MessageEvent) => {
|
||||
if (evt.origin === window.origin) {
|
||||
const msg: ToVariantAnalysisMessage = evt.data;
|
||||
if (msg.t === 'setVariantAnalysis') {
|
||||
@@ -89,7 +89,12 @@ export function VariantAnalysis({
|
||||
const origin = evt.origin.replace(/\n|\r/g, '');
|
||||
console.error(`Invalid event origin ${origin}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
window.addEventListener('message', listener);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('message', listener);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (variantAnalysis?.actionsWorkflowRunId === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user