@@ -99,6 +99,8 @@ class MarkdownElement extends LightElement {
9999 protected willUpdate ( changedProperties : PropertyValues ) : void {
100100 if ( changedProperties . has ( "content" ) ) {
101101 this . #isContentBeingAdded = true ;
102+
103+ MarkdownElement . #doUnBind( this ) ;
102104 }
103105 super . willUpdate ( changedProperties ) ;
104106 }
@@ -115,9 +117,9 @@ class MarkdownElement extends LightElement {
115117 // Render Shiny HTML dependencies and bind inputs/outputs
116118 if ( this . streaming ) {
117119 this . #appendStreamingDot( ) ;
118- MarkdownElement . _throttledShinyBind ( this ) ;
120+ MarkdownElement . _throttledBind ( this ) ;
119121 } else {
120- MarkdownElement . #doShinyBind ( this ) ;
122+ MarkdownElement . #doBind ( this ) ;
121123 }
122124
123125 // Update scrollable element after content has been added
@@ -160,33 +162,47 @@ class MarkdownElement extends LightElement {
160162 this . querySelector ( `svg.${ SVG_DOT_CLASS } ` ) ?. remove ( ) ;
161163 }
162164
163- static async #doShinyBind( el : HTMLElement ) : Promise < void > {
165+ static async #doUnBind( el : HTMLElement ) : Promise < void > {
166+ if ( ! window . Shiny ) return ;
167+ if ( ! Shiny . unbindAll ) return ;
168+
169+ try {
170+ Shiny . unbindAll ( el ) ;
171+ } catch ( err ) {
172+ showShinyClientMessage ( {
173+ status : "error" ,
174+ message : `Failed to unbind Shiny inputs/outputs: ${ err } ` ,
175+ } ) ;
176+ }
177+ }
178+
179+ static async #doBind( el : HTMLElement ) : Promise < void > {
164180 if ( ! window . Shiny ) return ;
165181 if ( ! Shiny . initializeInputs ) return ;
166182 if ( ! Shiny . bindAll ) return ;
167183
168184 try {
169185 Shiny . initializeInputs ( el ) ;
170- } catch ( initError ) {
186+ } catch ( err ) {
171187 showShinyClientMessage ( {
172188 status : "error" ,
173- message : `Failed to initialize Shiny inputs: ${ initError } ` ,
189+ message : `Failed to initialize Shiny inputs: ${ err } ` ,
174190 } ) ;
175191 }
176192
177193 try {
178194 await Shiny . bindAll ( el ) ;
179- } catch ( bindError ) {
195+ } catch ( err ) {
180196 showShinyClientMessage ( {
181197 status : "error" ,
182- message : `Failed to bind Shiny inputs/outputs: ${ bindError } ` ,
198+ message : `Failed to bind Shiny inputs/outputs: ${ err } ` ,
183199 } ) ;
184200 }
185201 }
186202
187203 @throttle ( 200 )
188- private static async _throttledShinyBind ( el : HTMLElement ) : Promise < void > {
189- await this . #doShinyBind ( el ) ;
204+ private static async _throttledBind ( el : HTMLElement ) : Promise < void > {
205+ await this . #doBind ( el ) ;
190206 }
191207
192208 #highlightAndCodeCopy( ) : void {
0 commit comments