File tree Expand file tree Collapse file tree 2 files changed +25
-10
lines changed
Expand file tree Collapse file tree 2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -26,17 +26,19 @@ function beforeNodeRemoved(node) {
2626}
2727
2828function beforeNodeMorphed ( target , newElement ) {
29- if ( target instanceof HTMLElement && ! target . hasAttribute ( "data-turbo-permanent" ) ) {
30- const event = dispatch ( "turbo:before-morph-element" , {
31- cancelable : true ,
32- target,
33- detail : {
34- newElement
35- }
36- } )
37- return ! event . defaultPrevented
29+ if ( target instanceof HTMLElement ) {
30+ if ( ! target . hasAttribute ( "data-turbo-permanent" ) ) {
31+ const event = dispatch ( "turbo:before-morph-element" , {
32+ cancelable : true ,
33+ target,
34+ detail : {
35+ newElement
36+ }
37+ } )
38+ return ! event . defaultPrevented
39+ }
40+ return false
3841 }
39- return false
4042}
4143
4244function beforeAttributeUpdated ( attributeName , target , mutationType ) {
Original file line number Diff line number Diff line change @@ -210,6 +210,19 @@ test("action=morph", async () => {
210210 assert . equal ( subject . find ( "h1#hello" ) ?. textContent , "Hello Turbo Morphed" )
211211} )
212212
213+ test ( "action=morph with text content change" , async ( ) => {
214+ const templateElement = createTemplateElement ( `<div id="hello">Hello Turbo Morphed</div>` )
215+ const element = createStreamElement ( "morph" , "hello" , templateElement )
216+
217+ assert . equal ( subject . find ( "div#hello" ) ?. textContent , "Hello Turbo" )
218+
219+ subject . append ( element )
220+ await nextAnimationFrame ( )
221+
222+ assert . ok ( subject . find ( "div#hello" ) )
223+ assert . equal ( subject . find ( "div#hello" ) ?. textContent , "Hello Turbo Morphed" )
224+ } )
225+
213226test ( "action=morph children-only" , async ( ) => {
214227 const templateElement = createTemplateElement ( `<h1 id="hello-child-element">Hello Turbo Morphed</h1>` )
215228 const element = createStreamElement ( "morph" , "hello" , templateElement )
You can’t perform that action at this time.
0 commit comments