[wp-trac] [WordPress Trac] #62628: Server and client directive negation logic should align

WordPress Trac noreply at wordpress.org
Mon Dec 2 11:55:16 UTC 2024


#62628: Server and client directive negation logic should align
-------------------------------+-----------------------------
 Reporter:  jonsurrell         |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Interactivity API  |    Version:  6.5
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 Interactivity API directives allow for a negation prefix `!`. Values with
 this prefix should be negated.

 [https://github.com/WordPress/wordpress-
 develop/blob/e89e279e0328eca38cd9cc4baff36e042afe3373/src/wp-includes
 /interactivity-api/class-wp-interactivity-api.php#L649-L650 The server
 side] and
 [https://github.com/WordPress/gutenberg/blob/8d343d155c7577d46aea33e708dceb39c571cc80/packages/interactivity/src/hooks.tsx#L246
 client side] negation logic both rely on rudimentary `!` negation. This
 means that the negation logic depends on PHP and JavaScript behavior which
 do not always agree and cause differences in server/client rendering of
 the same data.

 For example, with this state:

 {{{#!php
 <?php
 wp_interactivity_state(
         'example',
         array(
                 'emptyArray' => array(),
                 'stringZero' => '0',
         )
 );
 }}}

 And the following HTML with directives:

 {{{#!xml
 <div data-wp-interactive="example">
         <div data-wp-bind--data-test="!state.emptyArray"></div>
         <div data-wp-bind--data-test="!state.stringZero"></div>
 </div>
 }}}

 This is the server render render:

 {{{#!xml
 <div data-test="true" data-wp-bind--data-test="!state.emptyArray"></div>
 <div data-test="true" data-wp-bind--data-test="!state.stringZero"></div>
 }}}

 While the client renders the following:

 {{{#!xml
 <div data-test="false" data-wp-bind--data-test="!state.emptyArray"></div>
 <div data-test="false" data-wp-bind--data-test="!state.stringZero"></div>
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62628>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list