Skip to content

Render min repeater rows when no rows are stored - #138

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:fix/repeater-min-rows
Oct 19, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:fix/repeater-min-rows

Conversation

@Contributolo

@Contributolo Contributolo commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

A repeater with min and no stored rows renders false on the frontend instead of min rows of field defaults.

Cause

Block::transform() fills such a repeater from the built attribute:

if ( 'repeater' === ( $v['field'] ?? '' ) && ! isset( $v['default'] ) && ! empty( $v['min'] ) ) {

Container_Field_Handler::build_repeater() never copies min into that attribute; the built repeater only has blockstudio, type, field, id, attributes, plus default / fallback. The old attribute builder in build.php did copy it (added in 8af8909, "fix min rows"), and it went away with that builder in 3e1c3da (7.5.0 housekeeping). So since 7.5.0 the branch never runs.

It shows wherever a block renders without rows the editor saved: bs_render_block(), block tags, page sources, content written by scripts. The min-rows E2E test (tests/e2e/types/repeater/default-rows.ts) inserts the block in the editor, which adds the rows itself, so it still passes.

Found while building #137: the built repeater carries neither min nor max, so the validator there leaves row counts out.

Fix

Copy min into the built repeater attribute in build_repeater(). max is not read on the server, so it stays out.

Tests

  • AttributeBuilderTest::test_build_repeater_keeps_min.
  • tests/unit/block/BlockRepeaterMinRowsTest.php: a block with a min: 2 repeater renders two rows of field defaults when nothing is stored; stored rows and a repeater default still win. The first test fails without the fix (template gets false), both pass with it.

Run in WordPress Playground (PHP 8.4, WordPress latest, plugin and test theme mounted as in tests/wp-env): the new tests and attribute-builder green; build, register, extensions, wpml, render, populate, field, rest, block-merger and the block classes give the same results as unchanged main (the failures there are the same tests on main, environment related). composer cs and PHPStan on the changed file clean.

Block::transform() fills a repeater without stored rows with min rows of
field defaults, but it reads min from the built attribute, and
Container_Field_Handler::build_repeater() never copied it there. The old
attribute builder in build.php did, until it was removed in 7.5.0. Since
then a repeater with min and no stored rows renders false, for example in
bs_render_block(), block tags and page sources. The editor adds the rows
itself, so the min-rows E2E test still passed.

Copy min into the built repeater attribute, with a builder test and a
render test (both rows of field defaults, stored rows and default still
win).
dnnsjsk added a commit that referenced this pull request Oct 19, 2026
Port PR #138 and incorporate the render-path corrections from PR #137 into the existing #135 validator. Preserve read-only validation, original stored values, palette strings, dynamic-option exclusions and the CLI. Document repeater initial rows and storage precedence, with unit/render and CI-only HTTP coverage.

Co-authored-by: Contributolo <[email protected]>
@dnnsjsk
dnnsjsk merged commit 86a311c into inline0:main Oct 19, 2026
@dnnsjsk

dnnsjsk commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Merged and released in 7.7.5 (86a311c1). Repeater min now reaches the existing server-side initial-row logic. Explicit defaults and stored values, including an empty saved list, remain authoritative; rendering does not write rows back to the database.

Regression tests cover PHP embeds, block tags, the file-page parsing path, and a frontend HTTP request without an editor save. full CI passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants