Make WordPress Core

Opened 6 weeks ago

Closed 4 weeks ago

#61741 closed defect (bug) (fixed)

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

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

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.


6 weeks 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
6 weeks ago

  • Keywords has-unit-tests added

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


6 weeks ago

#4 @luisherranz
6 weeks ago

  • Owner set to luisherranz
  • Resolution set to fixed
  • Status changed from new to 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:


6 weeks ago
#5

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

Thanks, Jon 🙂

#6 @luisherranz
6 weeks ago

  • Keywords dev-feedback added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 6.6.2 consideration.

#7 follow-up: @adamsilverstein
6 weeks ago

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

#8 in reply to: ↑ 7 @jonsurrell
6 weeks ago

Replying to adamsilverstein:

should the @since line read 6.6.2? +1 to backporting.

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.

Version 0, edited 6 weeks ago by jonsurrell (next)

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


5 weeks ago

#10 @gziolo
5 weeks 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.


4 weeks ago

#12 @luisherranz
4 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to 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.