#62582 closed enhancement (fixed)
Support length property on strings and arrays on the server
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8 | Priority: | normal |
Severity: | normal | Version: | 6.5 |
Component: | Interactivity API | Keywords: | has-patch has-unit-tests has-dev-note |
Focuses: | Cc: |
Description (last modified by )
The Interactivity API does not support the .length
property on numeric arrays or strings on the server. This is one place where the behavior of server rendering is markedly different from client side rendering. The Interactivity API tries to align client and server rendering so that the behavior is the same.
String and array have a .length
property in JavaScript that the directives processor can provide in order to support directives like the following:
<div data-wp-interactive="example"> <div data-wp-bind--hidden="!state.list.length"> <input type="range" min="1" data-wp-bind--max="state.list.length"> </div> <div data-wp-bind--hidden="!state.string.length"> <h1 data-wp-text="state.string"></h1> </div> </div>
Testing for falsy .length
is a common JavaScript idiom.
Change History (9)
This ticket was mentioned in PR #7751 on WordPress/wordpress-develop by @jonsurrell.
5 months ago
#1
- Keywords has-patch added
@jonsurrell commented on PR #7751:
5 months ago
#2
This is ready for review @luisherranz @michalczaplinski @darerodz @cbravobernal.
This ticket was mentioned in Slack in #meta-tracdev by jonsurrell. View the logs.
5 months ago
#6
@
5 months ago
- Owner set to gziolo
- Resolution set to fixed
- Status changed from new to closed
In 59477:
5 months ago
#8
Committed with https://core.trac.wordpress.org/changeset/59477.
#9
@
4 weeks ago
- Keywords has-dev-note added; needs-dev-note removed
Note that the dev note has been published as Interactivity API best practices in 6.8.
Add
.length
to directives processing on the server on strings and numeric arrays.Trac ticket: https://core.trac.wordpress.org/ticket/62582