From d3cf7c449152e7360f63da33cb420209d6814fe4 Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Tue, 12 Jul 2022 10:25:23 -0600 Subject: [PATCH] fix for https://github.com/phetsims/natural-selection/issues/315 --- js/common/model/PopulationModel.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/common/model/PopulationModel.js b/js/common/model/PopulationModel.js index 45ff87b2..032b25fb 100644 --- a/js/common/model/PopulationModel.js +++ b/js/common/model/PopulationModel.js @@ -181,10 +181,14 @@ class PopulationModel extends PhetioObject { // Scrolls the x-axis so that 'now' is always the max x value. unlink is not necessary. timeInGenerationsProperty.link( timeInGeneration => { - const max = Math.max( options.xAxisLength, timeInGeneration ); - if ( this.xRangeProperty.value.max !== max ) { - const min = max - options.xAxisLength; - this.xRangeProperty.value = new Range( min, max ); + + // Skip when restoring PhET-iO state, see https://github.com/phetsims/natural-selection/issues/315 + if ( !phet.joist.sim.isSettingPhetioStateProperty.value ) { + const max = Math.max( options.xAxisLength, timeInGeneration ); + if ( this.xRangeProperty.value.max !== max ) { + const min = max - options.xAxisLength; + this.xRangeProperty.value = new Range( min, max ); + } } } );