Skip to content

Commit

Permalink
Fix "dead state tree node" error by creating snapshots of parent regi…
Browse files Browse the repository at this point in the history
…on for block calculations (#3182)

Ensure parentRegion gets a snapshot
  • Loading branch information
cmdcolin committed Sep 14, 2022
1 parent b1d1558 commit 563543e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/core/util/calculateDynamicBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isStateTreeNode, getSnapshot } from 'mobx-state-tree'
import { intersection2 } from './range'
import { assembleLocString } from '.'
import {
Expand Down Expand Up @@ -60,6 +61,7 @@ export default function calculateDynamicBlocks(
displayedRegionLeftPx + (regionEnd - regionStart) / bpPerPx

const regionWidthPx = (regionEnd - regionStart) / bpPerPx
const parentRegion = isStateTreeNode(region) ? getSnapshot(region) : region

if (
displayedRegionLeftPx < windowRightPx &&
Expand Down Expand Up @@ -104,7 +106,7 @@ export default function calculateDynamicBlocks(
end,
reversed,
offsetPx: blockOffsetPx,
parentRegion: region,
parentRegion,
regionNumber,
widthPx,
isLeftEndOfDisplayedRegion,
Expand Down
7 changes: 5 additions & 2 deletions packages/core/util/calculateStaticBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isStateTreeNode, getSnapshot, Instance } from 'mobx-state-tree'
import { assembleLocString } from '.'
import {
BlockSet,
Expand All @@ -6,11 +7,12 @@ import {
InterRegionPaddingBlock,
} from './blockTypes'
import { Region } from './types'
import { Region as RegionModel } from './types/mst'

export interface Base1DViewModel {
offsetPx: number
width: number
displayedRegions: Region[]
displayedRegions: (Region | Instance<typeof RegionModel>)[]
bpPerPx: number
minimumBlockWidth: number
interRegionPaddingWidth: number
Expand Down Expand Up @@ -54,6 +56,7 @@ export default function calculateStaticBlocks(
reversed,
} = region
const regionBlockCount = Math.ceil((regionEnd - regionStart) / blockSizeBp)
const parentRegion = isStateTreeNode(region) ? getSnapshot(region) : region

let windowRightBlockNum =
Math.floor((windowRightBp - regionBpOffset) / blockSizeBp) + extra
Expand Down Expand Up @@ -97,7 +100,7 @@ export default function calculateStaticBlocks(
end,
reversed,
offsetPx: (regionBpOffset + blockNum * blockSizeBp) / bpPerPx,
parentRegion: region,
parentRegion,
regionNumber,
widthPx,
isLeftEndOfDisplayedRegion,
Expand Down

0 comments on commit 563543e

Please sign in to comment.