···4646 useEffect(() => {
4747 setUIState('loading');
48484949- const containsStatus = statuses.find((s) => s.id === id);
5050- if (!containsStatus) {
5151- // Case 1: On first load, or when navigating to a status that's not cached at all
5252- setStatuses([{ id }]);
4949+ const cachedStatuses = store.session.getJSON('statuses-' + id);
5050+ if (cachedStatuses) {
5151+ // Case 1: It's cached, let's restore them to make it snappy
5252+ const reallyCachedStatuses = cachedStatuses.filter(
5353+ (s) => states.statuses.has(s.id),
5454+ // Some are not cached in the global state, so we need to filter them out
5555+ );
5656+ setStatuses(reallyCachedStatuses);
5357 } else {
5454- const cachedStatuses = store.session.getJSON('statuses-' + id);
5555- if (cachedStatuses) {
5656- // Case 2: Looks like we've cached this status before, let's restore them to make it snappy
5757- const reallyCachedStatuses = cachedStatuses.filter(
5858- (s) => snapStates.statuses.has(s.id),
5959- // Some are not cached in the global state, so we need to filter them out
6060- );
6161- setStatuses(reallyCachedStatuses);
6262- } else {
6363- // Case 3: Unknown state, could be a sub-comment. Let's slice off all descendant statuses after the hero status to be safe because they are custom-rendered with sub-comments etc
6464- const heroIndex = statuses.findIndex((s) => s.id === id);
5858+ const heroIndex = statuses.findIndex((s) => s.id === id);
5959+ if (heroIndex !== -1) {
6060+ // Case 2: It's in current statuses. Slice off all descendant statuses after the hero status to be safe
6561 const slicedStatuses = statuses.slice(0, heroIndex + 1);
6662 setStatuses(slicedStatuses);
6363+ } else {
6464+ // Case 3: Not cached and not in statuses, let's start from scratch
6565+ setStatuses([{ id }]);
6766 }
6867 }
6968