[wp-trac] [WordPress Trac] #60761: Interactivity API: Empty state objects are not correctly sent to the client

WordPress Trac noreply at wordpress.org
Tue Mar 12 17:48:21 UTC 2024


#60761: Interactivity API: Empty state objects are not correctly sent to the client
--------------------------+-----------------------------
 Reporter:  jonsurrell    |      Owner:  jonsurrell
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 If an Interactivity API store is created on the server with an empty
 array:

 {{{#!php
 wp_interactivity_state( 'myPlugin', array() );
 }}}

 It is serialized and sent to the client as a JavaScript array: `[]`.
 However, state is expected to be an object `{}`. This creates problems on
 the client when server and client states are merged. For example, it
 breaks state getters defined on the client like this:

 {{{
 store( "myplugin/demo", {
   state: {
     get aValue() {
       return 'This will break.';
     },
   }
 } );
 }}}

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


More information about the wp-trac mailing list