Skip to content

feat(samples): add sample-size reporter for auto-fitting docs iframes#3996

Open
desig9stein wants to merge 6 commits into
masterfrom
mpopov/add-sample-size-reporter
Open

feat(samples): add sample-size reporter for auto-fitting docs iframes#3996
desig9stein wants to merge 6 commits into
masterfrom
mpopov/add-sample-size-reporter

Conversation

@desig9stein

@desig9stein desig9stein commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Related to: IgniteUI/igniteui-astro-components#108

Demos on the docs site render inside cross-origin iframes. By default
styles.scss pins html/body to height:100% + overflow:hidden, so an
iframe can only ever echo its own height back — it can't grow to fit its
content. This adds the demo-side half of a small postMessage handshake
with the docs host (astro-components' sample-widget) so samples that opt
into fitContent size themselves to their actual content.

How it works:

  • the host posts { type: 'igd-sample-fit', width? } into the iframe on
    load; until that arrives the reporter stays completely dormant, so
    fixed-height demos and their percentage layouts are untouched
  • on enable, it injects a one-time stylesheet that releases the viewport
    pin (height:auto, overflow:visible) and reports content size back with
    { type: 'igd-sample-height', height, width? } immediately and on every
    resize (via ResizeObserver)
  • width is measured from the right-most element edge rather than the body
    box, mirroring the host's same-origin measurement, and is only computed
    when the host asks for it

Notes:

  • no-ops outside an iframe (window.parent === window) and when there is
    no window (SSR/prerender)
  • replies target the host's captured origin instead of broadcasting to
    '*', and only ever emit layout dimensions
  • shared across all three Angular apps (src, app-crm, app-lob) via the
    "@shared/sample-size-reporter" tsconfig path alias so there is a single
    source of truth

  Demos on the docs site render inside cross-origin iframes. By default
  styles.scss pins html/body to height:100% + overflow:hidden, so an
  iframe can only ever echo its own height back — it can't grow to fit its
  content. This adds the demo-side half of a small postMessage handshake
  with the docs host (astro-components' sample-widget) so samples that opt
  into fitContent size themselves to their actual content.

  How it works:
  - the host posts { type: 'igd-sample-fit', width? } into the iframe on
    load; until that arrives the reporter stays completely dormant, so
    fixed-height demos and their percentage layouts are untouched
  - on enable, it injects a one-time stylesheet that releases the viewport
    pin (height:auto, overflow:visible) and reports content size back with
    { type: 'igd-sample-height', height, width? } immediately and on every
    resize (via ResizeObserver)
  - width is measured from the right-most element edge rather than the body
    box, mirroring the host's same-origin measurement, and is only computed
    when the host asks for it

  Notes:
  - no-ops outside an iframe (window.parent === window) and when there is
    no window (SSR/prerender)
  - replies target the host's captured origin instead of broadcasting to
    '*', and only ever emit layout dimensions
  - shared across all three Angular apps (src, app-crm, app-lob) via the
    "@shared/sample-size-reporter" tsconfig path alias so there is a single
    source of truth
Comment thread src/sample-size-reporter.ts Fixed
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.

4 participants