[wp-trac] [WordPress Trac] #60744: 6.5-rc1: ref may be null from getElement() in style bindings

WordPress Trac noreply at wordpress.org
Mon Mar 11 11:21:51 UTC 2024


#60744: 6.5-rc1: ref may be null from getElement() in style bindings
--------------------------+------------------------------
 Reporter:  wongjn        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Themes        |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by wongjn):

 Seems to not be limited to just the `wp-style` binding nor derived state
 either:

 {{{
 <!-- wp:html -->
 <div data-wp-interactive="test">
   <div data-wp-bind--foo="state.foo"></div>
   <div data-wp-bind--foo="actions.foo"></div>
   <div data-wp-bind--foo="callbacks.foo"></div>
   <div data-wp-class--foo="state.foo"></div>
   <div data-wp-class--foo="actions.foo"></div>
   <div data-wp-class--foo="callbacks.foo"></div>
   <div data-wp-style--foo="state.foo"></div>
   <div data-wp-style--foo="actions.foo"></div>
   <div data-wp-style--foo="callbacks.foo"></div>
   <div data-wp-text="state.foo"></div>
   <div data-wp-text="actions.foo"></div>
   <div data-wp-text="callbacks.foo"></div>
 </div>
 <!-- /wp:html -->
 }}}

 With:

 {{{#!js
 import { store, getElement } from '@wordpress/interactivity';

 store( 'test', {
   state: {
     get foo() {
       const { ref } = getElement();
       console.log( 'state.foo:', ref );
     },
   },
   actions: {
     foo() {
       const { ref } = getElement();
       console.log( 'actions.foo:', ref );
     },
   },
   callbacks: {
     foo() {
       const { ref } = getElement();
       console.log( 'callbacks.foo:', ref );
     },
   },
 });
 }}}

 Produces:
 {{{
 state.foo: null
 actions.foo: null
 callbacks.foo: null
 tate.foo: null
 actions.foo: null
 callbacks.foo: null
 tate.foo: null
 actions.foo: null
 callbacks.foo: null
 tate.foo: null
 actions.foo: null
 callbacks.foo: null
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60744#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list