Skip to content

docs: replace homepage StackBlitz embed with docs-native counter demo - #59

Open
0xjcf wants to merge 1 commit into
mainfrom
docs/remove-stackblitz-embed
Open

docs: replace homepage StackBlitz embed with docs-native counter demo#59
0xjcf wants to merge 1 commit into
mainfrom
docs/remove-stackblitz-embed

Conversation

@0xjcf

@0xjcf 0xjcf commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Problem

The docs homepage embeds a StackBlitz project inline. On GitHub Pages the embed fails with "Unable to run Embedded Project" — StackBlitz/WebContainers require cross-origin isolation (COOP/COEP) headers that GitHub Pages does not send.

Fix (docs-only, no package changes)

  • Remove the inline StackBlitz iframe and its lazy-load script from the homepage.
  • Add a small docs-native live counter (CounterDemo.astro): a vanilla custom element with no dependencies and no iframe, mirroring the machine-backed <my-counter> example above it — buttons dispatch intent events, state owns the transition, the view re-renders from state.
  • Keep Open in StackBlitz and Open repo example as plain links.
  • Delete the now-unreferenced public/stackblitz-lazy.js and .stackblitz-embed CSS rule.

Verification

  • pnpm install --frozen-lockfile + astro build pass on this branch (18 pages).
  • Built index.html contains zero iframe/embed artifacts; the counter element and its inlined module script are present.
  • Identical demo logic was click-tested in a local browser preview (increment/decrement/reset, no console errors) on the v3 docs branch.

Notes

  • Merging this deploys the fix via the existing docs-deploy.yml push-to-main trigger. No npm release is implied.
  • This is a backport adapted to the v2 homepage. The v3 docs branch (fas/emitted-event-stream-seam, commits 49a19bf/2e0b17a) carries the richer version (real-API snippet, 2.x archive cleanup); the eventual merge supersedes this section cleanly.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added an interactive counter component with increment, decrement, and reset functionality to the documentation
  • Documentation

    • Updated the main documentation page's "Try it live" section with a new interactive counter example
    • Improved the demo presentation for better usability

The inline StackBlitz iframe fails on GitHub Pages ('Unable to run
Embedded Project') because StackBlitz/WebContainers need cross-origin
isolation (COOP/COEP) headers GitHub Pages does not send. Replace it
with a small docs-only custom-element counter that mirrors the
machine-backed example above it (state-driven view, commands as
intent), and keep 'Open in StackBlitz' / 'Open repo example' as plain
links. Delete the now-unreferenced stackblitz-lazy.js loader and
.stackblitz-embed CSS rule.

Backport of 49a19bf/2e0b17a from fas/emitted-event-stream-seam, adapted
to the v2 homepage (different surrounding content, no 2.x archive, no
geometry token layer on main).
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The PR replaces a StackBlitz iframe embed in the getting-started documentation with a custom web component counter. A new CounterDemo.astro component defines an interactive counter element (<docs-counter>) with increment, decrement, and reset buttons. The docs index now imports and renders this component instead of the inline embed, and removes the StackBlitz lazy-loader script and associated styling.

Changes

Interactive Counter Documentation

Layer / File(s) Summary
Counter demo component
docs/site/src/components/CounterDemo.astro
<docs-counter> custom element renders count output and control buttons; embedded DocsCounter class manages internal count state, initializes handlers in connectedCallback(), routes button clicks through a command switch in #send(), and updates the display via #render(). Component styling includes layout, typography, button states, and noscript fallback.
Documentation integration and cleanup
docs/site/src/content/docs/index.mdx, docs/site/src/styles/theme.css
Index imports CounterDemo and uses it in the "Try it live" section, replacing the inline StackBlitz embed with explanatory text and a rendered demo card; .stackblitz-embed CSS rule removed from theme; docs/site/public/stackblitz-lazy.js deleted entirely.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A counter hops in with buttons to click,
Increment, decrement, reset—oh, how quick!
StackBlitz is gone, its lazy days past,
A custom web element sparkles at last. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: replacing a StackBlitz embed with a docs-native counter demo component on the homepage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/remove-stackblitz-embed

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.20%. Comparing base (94a78b9) to head (440ce2d).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #59   +/-   ##
=======================================
  Coverage   95.20%   95.20%           
=======================================
  Files          32       32           
  Lines        1418     1418           
  Branches      388      388           
=======================================
  Hits         1350     1350           
  Misses         66       66           
  Partials        2        2           
Flag Coverage Δ
unittests 95.20% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/site/src/components/CounterDemo.astro`:
- Around line 32-40: Add a disconnectedCallback() to the CounterDemo custom
element that removes the click listeners added in connectedCallback(): iterate
the same this.querySelectorAll<HTMLButtonElement>("[data-command]") and call
removeEventListener with the exact handler reference used when adding them. To
ensure you have the same handler reference, store each handler when attaching
(e.g., on the button element or in a Map keyed by the button) so
disconnectedCallback can retrieve and remove it, then clear those stored
references; this mirrors the pattern used in the project's IgniteElement
cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5d6840e-cfa0-4ea1-b8f5-4470bc8bda47

📥 Commits

Reviewing files that changed from the base of the PR and between 94a78b9 and 440ce2d.

📒 Files selected for processing (4)
  • docs/site/public/stackblitz-lazy.js
  • docs/site/src/components/CounterDemo.astro
  • docs/site/src/content/docs/index.mdx
  • docs/site/src/styles/theme.css
💤 Files with no reviewable changes (2)
  • docs/site/public/stackblitz-lazy.js
  • docs/site/src/styles/theme.css

Comment on lines +32 to +40
connectedCallback() {
this.#output = this.querySelector(".counter-count");
for (const button of this.querySelectorAll<HTMLButtonElement>("[data-command]")) {
button.addEventListener("click", () => {
this.#send({ type: button.dataset.command ?? "" });
});
}
this.#render();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Add disconnectedCallback() to remove event listeners.

Event listeners are added in connectedCallback() but never removed, causing a memory leak if the element is disconnected and reconnected. The project's own IgniteElement base class demonstrates the proper pattern: disconnectedCallback() removes listeners to prevent leaks.

🔧 Proposed fix to add cleanup lifecycle method
	`#state` = { count: 0 };
	`#output`: HTMLElement | null = null;
+	`#listeners` = new Map<HTMLButtonElement, () => void>();

	connectedCallback() {
		this.#output = this.querySelector(".counter-count");
		for (const button of this.querySelectorAll<HTMLButtonElement>("[data-command]")) {
-			button.addEventListener("click", () => {
+			const handler = () => {
				this.#send({ type: button.dataset.command ?? "" });
-			});
+			};
+			button.addEventListener("click", handler);
+			this.#listeners.set(button, handler);
		}
		this.#render();
	}

+	disconnectedCallback() {
+		for (const [button, handler] of this.#listeners) {
+			button.removeEventListener("click", handler);
+		}
+		this.#listeners.clear();
+	}
+
	// Commands express intent; state transitions live here, not in the buttons.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/site/src/components/CounterDemo.astro` around lines 32 - 40, Add a
disconnectedCallback() to the CounterDemo custom element that removes the click
listeners added in connectedCallback(): iterate the same
this.querySelectorAll<HTMLButtonElement>("[data-command]") and call
removeEventListener with the exact handler reference used when adding them. To
ensure you have the same handler reference, store each handler when attaching
(e.g., on the button element or in a Map keyed by the button) so
disconnectedCallback can retrieve and remove it, then clear those stored
references; this mirrors the pattern used in the project's IgniteElement
cleanup.

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.

1 participant