Skip to content

fix(generator): size the split hero and preload eager code heroes - #1674

Merged
gregpriday merged 4 commits into
developfrom
bugfix/issue-1486-hero-image-preload-hardcodes-100vw-on
Nov 28, 2026
Merged

gregpriday merged 4 commits into
developfrom
bugfix/issue-1486-hero-image-preload-hardcodes-100vw-on

Conversation

@gregpriday

Copy link
Copy Markdown
Member

Foundation's split hero showed its picture in a 7/12 column from desktop up, yet its <img>, <source>s and the head's preload all said 100vw, so a 1440px screen fetched a full-width copy for a picture about 658px wide. The preload also knew only that one component by pack and ID, so a project's own code hero, or any other pack's, got no preload at all.

Resolves #1486

Changes

  • Split hero sizes. hero.split passes sizes="(min-width: 1024px) 59vw, 100vw" to its picture in both committed releases (foundation, foundation-alt), and resources/packs.lock.json is re-pinned. 59vw is 7/12 rounded up. It holds for the media-start layout too, and it is an upper estimate, since the container's maximum width is a token a site can change.
  • Any code hero can be preloaded. The hard-coded Foundation case in heroImage is gone. A code placement in the first section counts in its turn, on the page or inside a design. eagerCodeImage (src/generator/checks.ts) reads its source, and the head asks for the picture with the sizes the markup writes (none means the runtime's 100vw). It needs all of these:
    • its one image property is shown by the one runtime image, imported from runtime/Image.svelte under any name, as itself, a copy with settings added, or thumbnail(...);
    • that image loads eagerly (eager, eager={true}, or eager={so_eager} where the page hands the flag);
    • it sits outside every block but {#key} and every other component's content, with no picture before it;
    • it takes only attributes that leave the picture and its loading alone;
    • its sizes is a plain written list.
  • Conservative where unreadable. Anything else (blocks, spreads, computed sizes, a renamed or shadowed property, flag or helper) gets no preload. Code that may load a picture eagerly in a way the head cannot read ends the walk with none, rather than preloading a later picture than the one the page loads first.
  • Walk boundary. Nothing inside a code placement (its slot content) is walked, since only its markup decides where that shows.
  • shownOf is shared with showsWithSoImage, which now also declines computed keys such as ['sources'] in a copy.

Component source and the release lock

The source change is in siteorigin/builder-components#59, based on feat/builder-997-editor-hooks like #1562 and #1598. As there, the releases were edited directly rather than rebuilt, and builderComponentsCommit is unchanged. The committed hero.split also carries the #1432 print rule, which the component source still lacks.

Testing

  • tests/unit/picture-markup.test.ts:
    • The split hero's picture is now sized by its column. This was the it.fails release gap, now an ordinary test.
    • The release hero's preload matches its first source exactly.
    • New cases cover a project code hero: literal sizes, a forwarded flag on the page and through a design, a thumbnail, a copy with settings added, and slotted placement.
    • Thirteen markup shapes and three scripts that must not preload are covered, along with a flag the page never hands, slot content code never shows, and the walk stopping after unreadable code or continuing after lazy code.
  • tests/unit/generator.test.ts: the split hero's emitted tag carries the sizes. The foundation-alt assertion now expects the source's own sizes, and the remaining release gap is narrowed to testimonial portraits.
  • The new preload tests failed before the generator change and pass after it.
  • Impact slice: 58 of 579 unit test files (10%), all green. Type check green. Tests covering src/generator/index.ts were rerun after rebasing onto develop.
  • The repository has no lint or Prettier config, so neither ran.

Left open

  • eagerCodeImage is a token-level reader, not Svelte's parser, which would pull the compiler into the renderer bundle. Deliberately adversarial sources can still fool it, such as an import-looking line inside a multi-line script string, a regex literal containing {/if}, or <svelte:element this={'img'}> before the picture.
  • eager={false} on a code picture with a chosen image ends the walk with no preload, even though a later picture would have been safe to preload.
  • Foundation's hero.screenshot and content.media write no sizes, so they are now preloaded at the runtime's 100vw, matching their bodies. block.feature is not readable and gets no preload.

…heroes

- Give Foundation's hero.split picture the sizes of its column, in both committed releases, and re-pin the lock
- Read a code placement's eager picture and its written sizes for the head's preload, in place of the one hard-coded hero
- Walk code placements in the first section, inside designs too, and leave their slot content alone
…ly loads it

- Read the markup in order, skipping expressions, strings and comments, and decline blocks, other components' content, an earlier picture, attributes that change the picture, and properties the script renames
- End the walk with no preload after code that loads a picture eagerly in a way the head cannot read
- Leave everything inside a code placement out of the first section's walk
…reload

- Decline a bare or escaped sizes, a {@const}, comments in the image expression, logical assignments to the property and a helper renamed to thumbnail
- End the walk after code that has a picture of its own the head cannot read
- Test a flag the page never hands, slot content code never shows, and a renamed helper
…() statement

- Stop the properties' destructuring at its statement, so an earlier destructuring of something else is never read as them
- Leave commented-out markup out of the check for a code placement's own picture
- Test a native picture before the section's next one, and a property taken from elsewhere
@gregpriday
gregpriday force-pushed the bugfix/issue-1486-hero-image-preload-hardcodes-100vw-on branch from d9afc20 to 8b0a46d Compare November 28, 2026 10:12
@gregpriday
gregpriday merged commit 4b2ef85 into develop Nov 28, 2026
1 check failed
@gregpriday
gregpriday deleted the bugfix/issue-1486-hero-image-preload-hardcodes-100vw-on branch November 28, 2026 10:20
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.

Hero image preload hardcodes 100vw on split heroes and omits preload tags for custom code heroes

1 participant