Skip to content

Commit

Permalink
fix(test): flake in telemetry
Browse files Browse the repository at this point in the history
clear the timeout when the component is destroyed
else we may have code being executed once environment is gone

fixes #3567
Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Sep 29, 2023
1 parent 381a629 commit fe7c8fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/renderer/src/Route.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { TinroBreadcrumb, TinroRouteMeta } from 'tinro';
import { TelemetryService } from './TelemetryService';
import { lastPage, currentPage, listPage, detailsPage } from './stores/breadcrumb';
import type { NavigationHint } from './Route';
import { onDestroy } from 'svelte';
export let path = '/*';
export let fallback = false;
Expand Down Expand Up @@ -71,6 +72,10 @@ $: route.update({
firstmatch,
breadcrumb,
});
onDestroy(() => {
TelemetryService.getService().handlePageClose();
});
</script>

{#if showContent}
Expand Down
13 changes: 9 additions & 4 deletions packages/renderer/src/TelemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ export class TelemetryService {
private handlerFlusher: NodeJS.Timeout | undefined;

public handlePageOpen(pagePath: string) {
if (this.handlerFlusher !== undefined) {
clearTimeout(this.handlerFlusher);
this.handlerFlusher = undefined;
}
this.handlePageClose();

this.handlerFlusher = setTimeout(() => {
if (window.telemetryPage) {
Expand All @@ -46,4 +43,12 @@ export class TelemetryService {
}
}, 200);
}

// clear timeout
public handlePageClose() {
if (this.handlerFlusher) {
clearTimeout(this.handlerFlusher);
this.handlerFlusher = undefined;
}
}
}

0 comments on commit fe7c8fb

Please sign in to comment.