Skip to content

Commit 9cbe8ba

Browse files
committed
change setTimeout usages to callback functions and remove vestigial code
Signed-off-by: Matt Nelson <[email protected]>
1 parent 661a7ba commit 9cbe8ba

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/components/view/view-event-list.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,17 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
769769
private listBodyRef = React.createRef<HTMLDivElement>();
770770
private listRef = React.createRef<List>();
771771

772+
private setListBodyRef = (element: HTMLDivElement | null) => {
773+
// Update the ref
774+
(this.listBodyRef as any).current = element;
775+
776+
// If the element is being mounted and we haven't restored state yet, do it now
777+
if (element && !this.hasRestoredInitialState) {
778+
this.restoreScrollPosition();
779+
this.hasRestoredInitialState = true;
780+
}
781+
};
782+
772783
private KeyBoundListWindow = observer(
773784
React.forwardRef<HTMLDivElement>(
774785
(props: any, ref) => <div
@@ -818,7 +829,7 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
818829
: <AutoSizer>{({ height, width }) =>
819830
<Observer>{() =>
820831
<List
821-
innerRef={this.listBodyRef}
832+
innerRef={this.setListBodyRef}
822833
outerElementType={this.KeyBoundListWindow}
823834
ref={this.listRef}
824835

@@ -896,21 +907,8 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
896907
});
897908
}
898909

899-
private hasRestoredInitialState = false;
900-
componentDidMount() {
901-
// Don't save scroll state immediately - wait until we've restored first
902-
903-
// Use a more aggressive delay to ensure DOM is fully ready
904-
setTimeout(() => {
905-
this.restoreScrollPosition();
906-
907-
// Only start tracking scroll changes after we've restored
908-
setTimeout(() => {
909-
this.hasRestoredInitialState = true;
910-
}, 100);
911-
}, 100);
912-
}
913-
910+
private hasRestoredInitialState = false;
911+
914912
componentDidUpdate(prevProps: ViewEventListProps) {
915913
if (this.listBodyRef.current?.parentElement?.contains(document.activeElement)) {
916914
// If we previously had something here focused, and we've updated, update

src/components/view/view-page.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ class ViewPage extends React.Component<ViewPageProps> {
171171

172172
private listRef = React.createRef<ViewEventList>();
173173
private splitPaneRef = React.createRef<SplitPane>();
174+
175+
@observable
176+
private shouldRestoreViewStateOnRefSet = false;
174177

175178
@observable
176179
private searchFiltersUnderConsideration: FilterSet | undefined;
@@ -248,10 +251,8 @@ class ViewPage extends React.Component<ViewPageProps> {
248251
if (this.props.eventId && this.selectedEvent) {
249252
this.onScrollToCenterEvent(this.selectedEvent);
250253
} else if (!this.props.eventId && this.props.uiStore.selectedEventId) {
251-
// If no URL eventId but we have a persisted selection, restore it
252-
setTimeout(() => {
253-
this.listRef.current?.restoreViewState();
254-
}, 100);
254+
// If no URL eventId but we have a persisted selection, restore it when ref is set
255+
this.shouldRestoreViewStateOnRefSet = true;
255256
} else {
256257
this.onScrollToEnd();
257258
}
@@ -333,9 +334,6 @@ class ViewPage extends React.Component<ViewPageProps> {
333334
})
334335
);
335336
}
336-
componentWillUnmount() {
337-
// Component is unmounting
338-
}
339337

340338
componentDidUpdate(prevProps: ViewPageProps) {
341339
// Only clear persisted selection if we're explicitly navigating to a different event via URL
@@ -468,7 +466,7 @@ class ViewPage extends React.Component<ViewPageProps> {
468466
contextMenuBuilder={this.contextMenuBuilder}
469467
uiStore={this.props.uiStore}
470468

471-
ref={this.listRef}
469+
ref={this.setListRef}
472470
/>
473471
</LeftPane>
474472
<PaneOuterContainer
@@ -642,6 +640,19 @@ class ViewPage extends React.Component<ViewPageProps> {
642640
onScrollToEnd() {
643641
this.listRef.current?.scrollToEnd();
644642
}
643+
644+
@action.bound
645+
setListRef = (ref: ViewEventList | null) => {
646+
if (ref) {
647+
(this.listRef as any).current = ref;
648+
if (this.shouldRestoreViewStateOnRefSet) {
649+
this.shouldRestoreViewStateOnRefSet = false;
650+
ref.restoreViewState();
651+
}
652+
} else {
653+
(this.listRef as any).current = null;
654+
}
655+
};
645656
}
646657

647658
const LeftPane = styled.div`

0 commit comments

Comments
 (0)