Pinned button link (absolute, inset:0) loses authored width:max-content: generated width:100%!important clips the label

Abierto Apto para principiantes
#6,318 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
79/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php, wordpress
Área
backend, web-dev

Línea de trabajo

Empieza en php-transformer/src/HtmlToBlocks/Style/GeneratedBlockStyleProjector.php, leyendo la rama de dimensionamiento del contenedor del botón y sourceControlPinsToItsWrapper() junto con las comprobaciones del ancho definido que se mencionan en el issue. Usa B-button-max-content.html como fixture reducido y verifica que la regla generada conserve un ancho distinto de auto y mantenga la altura fijada; se considera terminado cuando el enlace importado sigue midiendo unos 186px de ancho y la etiqueta completa aparece sobre su fondo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

A source button link that is absolutely positioned with inset:0 inside a small sized wrapper, but also declares width:max-content; min-width:100%, is wider than its wrapper in the source. It sizes to its label. After import it becomes core/buttons > core/button, and a generated rule forces the link to width:100%!important. The link shrinks to the wrapper's width, and the label overflows on both sides. Light label text that overflows the button background disappears against the page, so the visible text is clipped. For example, "Get in touch with the team" renders as "n touch with the".

Owning stage: WordPress materialization (generated block style projection for lowered core/button).

Reduced fixture

B-button-max-content.html (standalone, CSS inline):

<!doctype html><html><head><meta charset="utf-8"><title>Button fixture</title><style>
body{margin:0;font-family:sans-serif}
.box{position:relative;width:110px;height:40px;margin:40px}
.btn{box-sizing:border-box;display:flex;align-items:center;justify-content:center;width:max-content;min-width:100%;background:#5d1ff2;color:#fff;white-space:nowrap}
[data-variant] .box .btn{position:absolute;inset:0}
</style></head><body><main><div data-variant="solid"><div class="box"><a class="btn" href="/about/">Get in touch with the team</a></div></div></main></body></html>

The [data-variant] ancestor in the positioning rule matters. It sends the rule through the attribute-ancestry selector projection, which keeps position:absolute; inset:0 on .wp-block-button__link, matching the source. The same rule written as a plain .box .btn moves position:absolute onto the .wp-block-buttons wrapper, without its inset. That wrapper then shrink-wraps to the label, which hides this bug by accident. Large captured sites hit the first path because their author rules carry attribute-gated ancestors.

Observed

Viewport 1280px, Chromium (Playwright), measured with getBoundingClientRect():

Wrapper width Link width Label text extent (x) Link extent (x)
Source 110 185.9 (max-content) 40 → 225.9 40 → 225.9
Imported 110 110 2.1 → 187.9 40 → 150

Imported block structure: core/group.box > core/buttons > core/button > a.wp-block-button__link (position:absolute; inset:0, from the projected author rule).

Winning generated rule:

.blocks-engine-control-<hash>-0.blocks-engine-control-<hash>-0>.wp-block-button__link{width:100%!important;height:100%!important;border-radius:0!important;text-align:start!important}

It overrides the projected author declaration width:max-content;min-width:100% on the same link.

The same thing happened on a full captured site: a 109px × 40px button wrapper whose link was 196px wide in the source became 109px after import.

Root cause

php-transformer/src/HtmlToBlocks/Style/GeneratedBlockStyleProjector.php (trunk ad346db3), in the button carrier sizing chain:

} elseif ( self::sourceControlPinsToItsWrapper($sourceDeclarations) ) {
    // The source control takes its box from a sized wrapper by pinning
    // to every edge. ...
    $outerWrapperDeclarations[] = 'height:100%';
    $wrapperDeclarations[] = 'height:100%';
    $declarations[] = 'width:100%!important';
    $declarations[] = 'height:100%!important';
}

sourceControlPinsToItsWrapper() (line ~631) only checks position:absolute and inset:0 (or all four edges set to 0). In CSS an absolutely positioned box with left:0; right:0 only fills its containing block when width is auto. If width is set to anything else, the box is over-constrained: right is ignored and the authored width wins. Here the source declares width:max-content and min-width:100%, so the box is at least as wide as the wrapper and grows to its label. The branch never checks $hasAuthoredWidth or the authored width value (both are computed earlier in the same method, line ~267). It emits width:100%!important, which turns "at least the wrapper" into "exactly the wrapper".

Expected

When the source control declares a non-auto width (for example max-content, fit-content, or a length), the pins-to-wrapper branch should not force width:100%!important. Keep the authored width and min-width:100%. The pinned height:100% behavior can stay. The imported link in the fixture should measure about 186px wide and show the full label on the button background, as in the source.

Reduced and filed with AI assistance (Claude, via coding agent).

Lenguaje dominante
PHP
Estrellas
28
Forks
5
Merge medio
2 h 59 min
PR fusionados (30 d)
942

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Automattic/blocks-engine

Todos los issues de Automattic/blocks-engine

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.