Skip to content

Commit

Permalink
Merge branch 'fix-use-saved-scroll-position-when-navigating-back-des-…
Browse files Browse the repository at this point in the history
…1592'
  • Loading branch information
raksooo committed Jan 14, 2025
2 parents ed0b9cd + 8f5415d commit 7fdaade
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const NavigationScrollbars = React.forwardRef(function NavigationScrollba
forwardedRef?: React.Ref<CustomScrollbarsRef>,
) {
const history = useHistory();
const location = useRef(history.location);
const { setNavigationHistory } = useAppContext();
const { onScroll } = useContext(NavigationScrollContext);

Expand All @@ -25,7 +26,7 @@ export const NavigationScrollbars = React.forwardRef(function NavigationScrollba

const beforeunload = useEffectEvent(() => {
if (ref.current) {
history.recordScrollPosition(ref.current.getScrollPosition());
location.current.state.scrollPosition = ref.current.getScrollPosition();
setNavigationHistory(history.asObject);
}
});
Expand All @@ -44,7 +45,7 @@ export const NavigationScrollbars = React.forwardRef(function NavigationScrollba

const onUnmount = useEffectEvent(() => {
if (history.action === 'PUSH' && ref.current) {
history.recordScrollPosition(ref.current.getScrollPosition());
location.current.state.scrollPosition = ref.current.getScrollPosition();
setNavigationHistory(history.asObject);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import styled from 'styled-components';

import { useAppContext } from '../../context';
Expand Down Expand Up @@ -66,13 +66,14 @@ export function ExpandableSection(props: ExpandableSectionProps) {
const { expandableId, expandedInitially, sectionTitle, ...otherProps } = props;

const history = useHistory();
const location = useRef(history.location);
const { setNavigationHistory } = useAppContext();
const expandedValue =
history.location.state.expandedSections[props.expandableId] ?? !!expandedInitially;
const [expanded, , , toggleExpanded] = useBoolean(expandedValue);

const updateHistory = useEffectEvent((expanded: boolean) => {
history.recordSectionExpandedState(props.expandableId, expanded);
location.current.state.expandedSections[props.expandableId] = expanded;
setNavigationHistory(history.asObject);
});

Expand Down
8 changes: 0 additions & 8 deletions desktop/packages/mullvad-vpn/src/renderer/lib/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ export default class History {
return history;
}

public recordScrollPosition(position: [number, number]) {
this.location.state.scrollPosition = position;
}

public recordSectionExpandedState(id: string, expanded: boolean) {
this.location.state.expandedSections[id] = expanded;
}

public get location(): Location<LocationState> {
return this.entries[this.index];
}
Expand Down

0 comments on commit 7fdaade

Please sign in to comment.