mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-16 20:43:48 +00:00
Fixed event source not being properly closed with new boundToMercureHub HOC
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import React, { FC, useEffect } from 'react';
|
import React, { FC, useEffect } from 'react';
|
||||||
|
import { pipe } from 'ramda';
|
||||||
import { CreateVisit } from '../../visits/types';
|
import { CreateVisit } from '../../visits/types';
|
||||||
import { MercureInfo } from '../reducers/mercureInfo';
|
import { MercureInfo } from '../reducers/mercureInfo';
|
||||||
import { bindToMercureTopic } from './index';
|
import { bindToMercureTopic } from './index';
|
||||||
@@ -21,11 +22,10 @@ export function boundToMercureHub<T = {}>(
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onMessage = (visit: CreateVisit) => interval ? pendingUpdates.add(visit) : createNewVisits([ visit ]);
|
const onMessage = (visit: CreateVisit) => interval ? pendingUpdates.add(visit) : createNewVisits([ visit ]);
|
||||||
|
const closeEventSource = bindToMercureTopic(mercureInfo, getTopicForProps(props), onMessage, loadMercureInfo);
|
||||||
bindToMercureTopic(mercureInfo, getTopicForProps(props), onMessage, loadMercureInfo);
|
|
||||||
|
|
||||||
if (!interval) {
|
if (!interval) {
|
||||||
return undefined;
|
return closeEventSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
@@ -33,7 +33,7 @@ export function boundToMercureHub<T = {}>(
|
|||||||
pendingUpdates.clear();
|
pendingUpdates.clear();
|
||||||
}, interval * 1000 * 60);
|
}, interval * 1000 * 60);
|
||||||
|
|
||||||
return () => clearInterval(timer);
|
return pipe(() => clearInterval(timer), () => closeEventSource?.());
|
||||||
}, [ mercureInfo ]);
|
}, [ mercureInfo ]);
|
||||||
|
|
||||||
return <WrappedComponent {...props} />;
|
return <WrappedComponent {...props} />;
|
||||||
|
|||||||
Reference in New Issue
Block a user