@@ -26,6 +26,7 @@ import './participant_help_panel';
2626import './participant_nav' ;
2727
2828import { MobxLitElement } from '@adobe/lit-mobx' ;
29+ import { reaction } from 'mobx' ;
2930import { CSSResultGroup , html , nothing } from 'lit' ;
3031import { customElement , property , state } from 'lit/decorators.js' ;
3132
@@ -64,6 +65,35 @@ export class ParticipantView extends MobxLitElement {
6465
6566 @state ( ) isStartExperimentLoading = false ;
6667
68+ private stageReactionDisposer ?: ( ) => void ;
69+
70+ override connectedCallback ( ) {
71+ super . connectedCallback ( ) ;
72+ this . stageReactionDisposer = reaction (
73+ ( ) => this . participantService . currentStageViewId ,
74+ async ( ) => {
75+ // Wait for Lit to re-render with the new stage component
76+ await this . updateComplete ;
77+ const previewer = this . shadowRoot ?. querySelector (
78+ '.participant-previewer' ,
79+ ) ;
80+ previewer ?. scrollTo ( 0 , 0 ) ;
81+ // Stage components have their own overflow:auto on :host,
82+ // so scroll the stage element too.
83+ previewer
84+ ?. querySelector (
85+ ':scope > :not(participant-header):not(participant-nav)' ,
86+ )
87+ ?. scrollTo ( 0 , 0 ) ;
88+ } ,
89+ ) ;
90+ }
91+
92+ override disconnectedCallback ( ) {
93+ super . disconnectedCallback ( ) ;
94+ this . stageReactionDisposer ?.( ) ;
95+ }
96+
6797 override render ( ) {
6898 const stageId = this . participantService . currentStageViewId ;
6999 const stage = this . experimentService . getStage ( stageId ?? '' ) ;
0 commit comments