Skip to content

onPageRendered: page.html is undefined for some pages during alloy dev initial build #1179

Description

@zeroedin

Description

During alloy dev initial build, some pages arrive at onPageRendered with page.html set to undefined (JavaScript) instead of an empty string or the rendered HTML.

Steps to reproduce

  1. Register an onPageRendered hook with the v0.6.0 object API:
    alloy.hook("onPageRendered", {}, (page) => {
      // page.html is undefined for some pages
      if (page.html.includes('something')) { ... }
    });
  2. Run alloy dev on a site with many pages (e.g., RHDS with 820 pages)
  3. The initial build fails with:
    TypeError: cannot read property 'includes' of undefined
        at <anonymous> (01-transforms.js:7:36)
    

Expected behavior

page.html should always be a string (empty "" is fine, undefined is not). The HookRenderedPayload struct uses json:"html" without omitempty, so Go should always serialize the field.

Workaround

Guard against undefined:

alloy.hook("onPageRendered", {}, (page) => {
  if (!page.html) return page;
  // ... transform page.html
});

Notes

  • alloy build works fine — the issue only appears during alloy dev initial build
  • The error occurs on "item 0" suggesting it may affect the first page in the batch
  • buildPageRenderedPayload() calls page.HTML() which returns empty string for nil RenderedBody — so the Go side should be sending "", not omitting the field

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions