Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#61741 closed defect (bug) (fixed)

Interactivity API: Directives cannot access derived state properties on the server

Reported by: jonsurrell Owned by: luisherranz
Priority: normal Milestone: 6.6.2
Component: Interactivity API Version: 6.6
Severity: normal Keywords: has-patch has-unit-tests dev-reviewed
Cc: Focuses:

Description

If a directives includes derived state in a non-final position, and this is implemented with server-side derived state, this causes an error and the directive is not processed correctly. For example:

<p data-wp-text="state.derivedState.property"></p>

Where the state might look something like this:

<?php
array(
  'derivedState' => function() {
    return array( 'property' => 'Hello, world!' );
  },
);

This will error and fail to process correctly on the server. On the client with derived state getters, this will work fine.

Change History (12)

This ticket was mentioned in ​PR #7075 on ​WordPress/wordpress-develop by ​@jonsurrell.


2 years ago
#1

  • Keywords has-patch added

In some cases, derived state returns and object. Directives may wish to
continue to access properties of the object. Support this behavior.

On the client, derived state is implemented as JavaScript getters. This
transparently supports traversing a directive value like this:

state.derivedState.property

We can support this behavior on the server by handling derived state at
whatever the current value is for evaluation.

Trac ticket: https://core.trac.wordpress.org/ticket/61741

#2 @gziolo
2 years ago

  • Keywords has-unit-tests added

This ticket was mentioned in ​Slack in #core-committers by luisherranz. ​View the logs.


2 years ago

#4 @luisherranz
2 years ago

  • Owner set to luisherranz
  • Resolution → fixed
  • Status new → closed

In 58825:

Interactivity API: Allow server derived state to appear in non-final position

In some cases, derived state returns an associative array. Directives may wish to continue to access properties of the associative array, when using the syntax state.arrayReturnedByClosure.property. This patch continues evaluating the path after the associative array has been returned by the Closure.

Props jonsurrell, luisherranz.

Fixes #61741.

​@luisherranz commented on ​PR #7075:


2 years ago
#5

Committed to Core in https://core.trac.wordpress.org/changeset/58825.

Thanks, Jon 🙂

#6 @luisherranz
2 years ago

  • Keywords dev-feedback added
  • Resolution fixed
  • Status closed → reopened

Reopening for 6.6.2 consideration.

#7 follow-up: @adamsilverstein
2 years ago

PR looks good to me @luisherranz - should the @since line read 6.6.2? +1 to backporting.

#8 in reply to: ↑ 7 @jonsurrell
2 years ago

Replying to adamsilverstein:

should the @since line read 6.6.2?

Support for derived state on the server was added in 6.6.0. I added @since 6.6.0 intentionally since it was omitted when the feature was introduced.

Last edited 2 years ago by jonsurrell (previous) (diff)

This ticket was mentioned in ​Slack in #core-committers by luisherranz. ​View the logs.


2 years ago

#10 @gziolo
2 years ago

  • Keywords dev-reviewed added; dev-feedback removed

It looks good to backport to WP 6.6.2.

This ticket was mentioned in ​Slack in #core-committers by luisherranz. ​View the logs.


2 years ago

#12 @luisherranz
2 years ago

  • Resolution → fixed
  • Status reopened → closed

In 58869:

Interactivity API: Allow server derived state to appear in non-final position

In some cases, derived state returns an associative array. Directives may wish to continue to access properties of the associative array, when using the syntax state.arrayReturnedByClosure.property. This patch continues evaluating the path after the associative array has been returned by the Closure.

Reviewed by adamsilverstein and gziolo.
Merges [58825] to the 6.6 branch.

Props jonsurrell, luisherranz, adamsilverstein, gziolo.

Fixes #61741.

Note: See TracTickets for help on using tickets.