Footer layout with a form and two images becomes one raw-HTML "Custom Gallery" block (generated_component_non_native_items)

Đang mở
#5,425 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend, web-dev

Hướng nghiên cứu

Start with GeneratedComponentLowering.php and SubtreeClassifier.php, especially nativeOrGeneratedBlock(), isEntirelyNativeComponent(), repeatableChildCount(), and the media gallery signal. Reproduce through ArtifactCompiler::compileFragment() with the reduced page described in the issue, then inspect the generated blocks and diagnostics. Done means the form remains available to provider materialization, native siblings stay native, and the reduced footer produces no generated gallery or collection raw HTML block; add the described regression assertions and check the related fixtures.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

A site footer laid out as two rows in a column container (a link row, then a row holding a newsletter <form> and two payment-method <img> icons) is turned into one generated raw-HTML block, <ns>/gallery-<sha256> ("Custom Gallery", block.json blocksEngine.editingSurface: raw_html). It is not lowered to core/group + core/paragraph/core/image and the form path. The diagnostic reason is generated_component_non_native_items. On the real import, this is the entire site footer in parts/footer.html (logo, social icons, <hr>, "Stay in the Loop" form, reCAPTCHA notice, 8 payment icons, copyright). The owner can only edit it as an HTML textarea. Because the form is frozen inside the raw HTML string, the form provider never sees it, so no Jetpack form is materialized either.

Two decisions combine to cause this:

  1. The candidate gate misreads a layout as a repeated gallery. GeneratedComponentCandidates::collectGeneratedComponentCandidates() marks the div.container.col once it is at least GENERATED_COMPONENT_MIN_SOURCE_DEPTH (14) levels below <body>, has repeated direct-child tags, and FallbackEmitter::isRepeatableContentComponent() is true. SubtreeClassifier scores the container as custom_block (score 4 vs custom_application 2, confidence 0.78), from two signals:
    • repeatable_children = 2: the two layout rows share the class cell row and both "carry text" (a link label in one, the button label in the other). They are not repeated content items.
    • media_gallery = true: any 2 <img> anywhere in the subtree count as a gallery, here two 24 px payment icons. This signal also gives the generated block its gallery- stem and the "Custom Gallery" title.
  2. One non-native item freezes the whole container. GeneratedComponentLowering::nativeOrGeneratedBlock() does try authorLayoutBlockFromElement(). Inside it, the <form> lowers to a form_requires_runtime preserved runtime island (core/html plus a fallback entry), which at shallow depth is later materialized as jetpack/contact-form. Because $nativeFallbacks is not empty and isEntirelyNativeComponent() rejects core/html, the native result is thrown away and the entire container, including its native-expressible siblings, goes to FallbackEmitter::maybeGenerateCustomBlock(..., preserveRoot: true, confirmedComponent: true).

Seen on a Square Online site import (dandiandidesigns.com; Studio 2.1.0-dev276 / Static Site Importer 1.33.507 / Data Liberation Agent 0.33.201). Also reproduces on Blocks Engine trunk 316ce5d41c (php-transformer 0.45.436) through ArtifactCompiler::compileFragment(). Similar gallery-* raw-HTML blocks appear in the page content of the same site.

Reduced page

index.html, plus a media/ folder holding any two small SVG/PNG files named visa.svg and mastercard.svg:

<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8"><title>Acme</title>
<style>
.row{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.col{display:flex;flex-direction:column;gap:16px}
.pay{width:38px;height:24px}
</style></head>
<body>
<div class="wrap"><div class="wrap"><div class="wrap"><div class="wrap"><div class="wrap"><div class="wrap">
<main><h1>Acme</h1><p>Welcome to Acme.</p></main>
<footer class="site-footer"><div class="wrap"><div class="wrap"><div class="wrap"><div class="wrap"><div class="wrap"><div class="wrap">
<div class="container col">
  <div class="cell row"><a href="mailto:[email protected]">Email</a></div>
  <div class="cell row">
    <form action="/subscribe" method="post"><input type="email" name="email" placeholder="Email"> <button type="submit">Sign Up</button></form>
    <img class="pay" src="media/visa.svg" alt="Visa"> <img class="pay" src="media/mastercard.svg" alt="Mastercard">
  </div>
</div>
</div></div></div></div></div></div></footer>
</div></div></div></div></div></div>
</body></html>

(The 12 .wrap divs only put .container.col at source depth 14, which matches the real Square Online DOM: body > div.app-container > … > footer > … > div.w-container.col.)

Steps

studio create --from ./reduced --path ./site --name footer-gallery --skip-browser

(reduced/ holds index.html + media/.) Or call (new ArtifactCompiler())->compileFragment(file_get_contents('reduced/index.html'), 'index.html') on trunk.

Observed

  • parts/footer.html is core/group(footer) > core/group > <ns>/gallery-a9a3a25f… and nothing else. The block's content attribute is the whole .container.col subtree as an HTML string, including the <form> and both <img> tags.
  • ssi-runtime/blocks/gallery-a9a3a25f…/block.json: "title": "Custom Gallery", "blocksEngine": {"editingSurface": "raw_html"}.
  • Diagnostics: preserved_runtime_island / form_requires_runtime, then generated_component_non_native_items ("Repeated content retained as generated raw HTML"), then raw_html_companion_block / generated_document_contains_raw_html_companion at selector div.container.col. raw_html_companion_block_count: 1. quality_pass: true, so the gate does not flag it.
  • SubtreeClassifier::classify(div.container.col): bucket=custom_block, confidence=0.78, repeatable_children=2, media_gallery=true, form_controls=1, scores={custom_block:4, custom_application:2}.

Controls, each from the same page with one change (Studio import + classifier):

Change Classifier Result
none (reduced page) custom_block 4 / app 2 → candidate 1 × gallery-<sha> raw HTML
<form> replaced by <span>Sign up below</span> custom_block 4 / 0 → candidate (same as above) native: group ×5, image ×2, paragraph ×2
<form> removed repeatable_children=1 → not a candidate native: gallery + image ×2
second <img> removed media_gallery=false, tie 2/2 → unknown native groups + image + form → jetpack/contact-form, jetpack/field-email

Full-footer bisection on the real capture showed the same pattern. Removing the social-icon row, the form, or the payment-icon row each gave a native footer. Removing only the logo still gave the raw-HTML gallery. In the original markup, the social <svg><title>Email</title><use …> icons are what make the first row "carry text".

Expected

  • A container whose children are a few dissimilar layout rows is not a "repeatable" component. A row of small payment or icon images is not a media_gallery that turns a footer into a "Custom Gallery".
  • When a candidate's native lowering contains a runtime island (here the form), the island stays a bounded island (core/html / provider-materialized form → jetpack/contact-form). Its native siblings (core/group, core/paragraph, core/image, core/separator, social links) stay native, rather than the whole container becoming one raw-HTML block.
  • For the reduced page: parts/footer.html contains core/group > core/paragraph/link + the form (Jetpack form after provider materialization) + 2 × core/image, with no gallery-*/collection-* raw_html block.

Likely owner

  • php-transformer/src/HtmlToBlocks/Elements/GeneratedComponentLowering.php, nativeOrGeneratedBlock() / isEntirelyNativeComponent(): this is all-or-nothing. A single form_requires_runtime island (core/html + $nativeFallbacks entry) discards the native lowering of the whole component.
  • php-transformer/src/HtmlToBlocks/Classification/SubtreeClassifier.php: repeatableChildCount() counts two layout rows with a shared class as repeated items, and media_gallery is "≥ 2 img|picture|figure|video anywhere in the subtree". Also FallbackEmitter::isRepeatableContentComponent() (threshold repeatable_children >= 2) and Support/GeneratedComponentCandidates.php.
  • Related: #4153 (depth-gated candidates freeze native-expressible repeats; open), #4232 and #4357 (earlier causes of generated_component_non_native_items freezing whole lists; closed).

Measurement

  • Regression test through ArtifactCompiler::compileFragment() with the reduced page: assert no block whose name matches /\/(gallery|collection)-[0-9a-f]{64}$/, assert a core/image per payment icon, and assert the form is still exposed to the form provider (a form_requires_runtime island or form metadata, not text inside a generated block's content). The test fails on trunk 316ce5d41c and passes with the fix.
  • Studio import of the reduced page: raw_html_companion_block_count: 0 and no generated_component_non_native_items diagnostic.
  • The <form>→<span> control keeps lowering natively, and the existing #4153/#4357 fixtures keep their current results.

Secondary findings (separate causes of the visual losses on the real footer)

These are not caused by the classification above, but they are why the frozen footer also renders badly. Both live in the companion-block render boundary that Static Site Importer generates (includes/class-static-site-importer-companion-plugin.php → ssi-runtime/blocks/*/render.php), so they probably belong in Automattic/static-site-importer:

  1. Two empty comments <!----> (Vue placeholders) corrupt the rest of the block. render.php calls wp_kses(). Its pre_kses filter wp_pre_kses_block_attributes() → filter_block_content() runs preg_replace_callback('%<!--(.*?)--->%', …). That regex spans from the first <!----> to the ---> of the next one, so a <!----> b <!----> c becomes a <!----> b <!--> c. KSES then outputs a b <!--&gt; c-->, and everything after the second empty comment becomes comment text. Measured on the real footer block: 16 <!----> in the content attribute became 7 <!--&gt; comment openers in render_block() output. They hide 7 of 8 payment icons, the reCAPTCHA notice, and several closing </div> tags, which collapses the form layout (Sign Up wraps under a narrow input). wp_kses_post('a <!----> b <!----> c') alone reproduces it on WordPress 7.1.4. Stripping HTML comments from generated content before the KSES boundary would avoid it.
  2. Sprite icons lose their <use>. The render boundary's SVG pass keeps href/xlink:href only for fragments whose id is inside the same <svg>. <use xlink:href="#email-icon"> points at a page-level <symbol> sprite, so the <use> is removed and the Email/Facebook/Instagram icons render as empty 24×24 boxes (the frontend also has no #email-icon symbol). Related: #4984 and #4797 (sprite sheets).

Reduced and filed by Claude (Anthropic) via the Franklin import-loop orchestrator; reduction verified with studio create --from.

Ngôn ngữ chính
PHP
Star
28
Fork
5
Merge trung bình
2 giờ 59 phút
Pull request đã merge (30 ngày)
942

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Automattic/blocks-engine

Tất cả issue của Automattic/blocks-engine

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.