Make WordPress Core

Opened 6 weeks ago

Last modified 6 weeks ago

#62628 new defect (bug)

Server and client directive negation logic should align

Reported by: jonsurrell's profile jonsurrell Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.5
Component: Interactivity API Keywords:
Focuses: Cc:

Description

Interactivity API directives allow for a negation prefix !. Values with this prefix should be negated.

The server side and 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
wp_interactivity_state(
        'example',
        array(
                'emptyArray' => array(),
                'stringZero' => '0',
        )
);

And the following HTML with directives:

<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:

<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:

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

Change History (2)

#2 @jonsurrell
6 weeks ago

This resource describes the behavior, "0" and [] may be the only problematic values:

https://www.php.net/manual/en/language.types.boolean.php

Note: See TracTickets for help on using tickets.