@@ -51,9 +51,6 @@ export function if_block(node, fn, elseif = false) {
5151 /** @type {DocumentFragment | null } */
5252 var offscreen_fragment = null ;
5353
54- /** @type {Effect | null } */
55- var pending_effect = null ;
56-
5754 function commit ( ) {
5855 if ( offscreen_fragment !== null ) {
5956 // remove the anchor
@@ -63,32 +60,22 @@ export function if_block(node, fn, elseif = false) {
6360 offscreen_fragment = null ;
6461 }
6562
66- if ( pending_effect ) {
67- if ( condition ) {
68- consequent_effect = pending_effect ;
69- } else {
70- alternate_effect = pending_effect ;
71- }
72- }
73-
74- var current_effect = condition ? consequent_effect : alternate_effect ;
75- var previous_effect = condition ? alternate_effect : consequent_effect ;
63+ var active = condition ? consequent_effect : alternate_effect ;
64+ var inactive = condition ? alternate_effect : consequent_effect ;
7665
77- if ( current_effect !== null ) {
78- resume_effect ( current_effect ) ;
66+ if ( active ) {
67+ resume_effect ( active ) ;
7968 }
8069
81- if ( previous_effect !== null ) {
82- pause_effect ( previous_effect , ( ) => {
70+ if ( inactive ) {
71+ pause_effect ( inactive , ( ) => {
8372 if ( condition ) {
8473 alternate_effect = null ;
8574 } else {
8675 consequent_effect = null ;
8776 }
8877 } ) ;
8978 }
90-
91- pending_effect = null ;
9279 }
9380
9481 const update_branch = (
@@ -122,18 +109,20 @@ export function if_block(node, fn, elseif = false) {
122109 offscreen_fragment . append ( ( target = create_text ( ) ) ) ;
123110 }
124111
125- if ( condition ? ! consequent_effect : ! alternate_effect ) {
126- pending_effect = fn && branch ( ( ) => fn ( target ) ) ;
112+ if ( condition ) {
113+ consequent_effect ??= fn && branch ( ( ) => fn ( target ) ) ;
114+ } else {
115+ alternate_effect ??= fn && branch ( ( ) => fn ( target ) ) ;
127116 }
128117
129118 if ( defer ) {
130119 var batch = /** @type {Batch } */ ( current_batch ) ;
131120
132- const skipped = condition ? alternate_effect : consequent_effect ;
133- if ( skipped !== null ) {
134- // TODO need to do this for other kinds of blocks
135- batch . skipped_effects . add ( skipped ) ;
136- }
121+ var active = condition ? consequent_effect : alternate_effect ;
122+ var inactive = condition ? alternate_effect : consequent_effect ;
123+
124+ if ( active ) batch . skipped_effects . delete ( active ) ;
125+ if ( inactive ) batch . skipped_effects . add ( inactive ) ;
137126
138127 batch . add_callback ( commit ) ;
139128 } else {
0 commit comments