Debug & Diagnostics

Inspect rendering behavior, understand output, and diagnose composition issues.

Overview

Rendering systems often fail in subtle ways. A missing class, a misplaced closing tag, a duplicated render, or a missing dependency can break a page without producing an obvious exception. PageBuilder includes diagnostic mechanisms to make these issues easier to identify and understand.

The goal of diagnostics in PageBuilder is not to replace the rendering model. It is to make the rendering model observable when you need to inspect what happened during page generation.

Why diagnostics matter

As soon as a rendering system becomes layered, debugging output becomes harder. A page may involve:

The outer document pipeline
Body capture through a temporary writer
Page-level dependency registration
Nested builders
Scoped Begin() / Dispose() rendering
Reusable CSS composers

When several of these mechanisms participate in the same page, it becomes important to know which builder rendered what, how many times it rendered, and whether the final output matches the intended structure.

Diagnostic goals

PageBuilder diagnostics help answer questions such as:

Which builder produced this HTML fragment?
Was this builder rendered once or multiple times?
Did the final output receive the expected attributes and classes?
Did a component register its page-level dependencies correctly?
Did rendering occur in the expected order?

Builder-level diagnostics

At the builder level, PageBuilder can expose metadata that helps identify the origin of rendered output. In debug scenarios, a builder can annotate its output with diagnostic attributes that make the rendering process easier to inspect directly in the browser.

Typical information includes:

The builder type that produced the fragment
A render counter showing how many times a builder instance rendered
Optional debug-oriented data-* attributes

Why render counters help

A common category of rendering bug is duplicate rendering. A component may render more than once because of an unexpected lifecycle path, an incorrect helper usage pattern, or a composition bug.

Render counter signal

If a fragment that should render once is shown with a higher render count, the issue becomes much easier to localize. This kind of signal is often more useful than a generic stack trace because it explains what happened in the final HTML output.

Diagnostics and the rendering pipeline

Diagnostics are especially useful in the PageBuilder pipeline because the final document is assembled in multiple stages. The body may be captured first, components may register dependencies during rendering, and the final document may be emitted only afterward.

In this model, debugging output is not only about visible HTML. It is also about understanding:

When body rendering happened
Which builders participated during capture
Whether page-level state was enriched as expected
Whether the final document structure matches the pipeline design

Diagnostics and PageInformation

Some rendering issues are not caused by the markup itself, but by missing page-level dependencies. A component may render correctly but fail functionally because its script or stylesheet was not registered into PageInformation .

When diagnosing such issues, you often need to inspect not only the final HTML, but also whether the correct page-level state was accumulated during rendering. Typical questions include:

Was the expected script file registered?
Was the stylesheet added to the page model?
Was inline JavaScript emitted in the correct section?

Typical categories of issues

Duplicate rendering
Unexpected rendering order
Missing or malformed attributes
Incorrect class composition
Missing page-level dependencies
Broken builder nesting
Invalid scoped rendering behavior

Recommended diagnostic workflow

When a rendering problem appears, a good debugging approach is usually:

Inspect the final HTML fragment in the browser
Check builder-level debug metadata, if enabled
Verify whether the fragment was rendered the expected number of times
Check whether the expected classes and attributes are present
Check whether the component registered the expected page-level dependencies
Confirm that the issue comes from rendering logic rather than CSS or JavaScript behavior alone

Diagnostics are for understanding, not for business logic

Diagnostic metadata should help explain output. It should not become part of normal application behavior. Rendering diagnostics exist to support development, framework evolution, and component debugging. They should remain a development aid rather than a dependency of the application itself.

Recommended usage

Use diagnostic metadata during framework development and component debugging
Inspect rendered HTML when debugging composition issues
Use render counters to detect duplicate rendering
Check PageInformation when diagnosing missing assets
Keep diagnostics separate from application logic