docs: replace homepage StackBlitz embed with docs-native counter demo - #59
docs: replace homepage StackBlitz embed with docs-native counter demo#590xjcf wants to merge 1 commit into
Conversation
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).
WalkthroughThe PR replaces a StackBlitz iframe embed in the getting-started documentation with a custom web component counter. A new ChangesInteractive Counter Documentation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
docs/site/public/stackblitz-lazy.jsdocs/site/src/components/CounterDemo.astrodocs/site/src/content/docs/index.mdxdocs/site/src/styles/theme.css
💤 Files with no reviewable changes (2)
- docs/site/public/stackblitz-lazy.js
- docs/site/src/styles/theme.css
| 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(); | ||
| } |
There was a problem hiding this comment.
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.
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)
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.public/stackblitz-lazy.jsand.stackblitz-embedCSS rule.Verification
pnpm install --frozen-lockfile+astro buildpass on this branch (18 pages).index.htmlcontains zero iframe/embed artifacts; the counter element and its inlined module script are present.Notes
docs-deploy.ymlpush-to-main trigger. No npm release is implied.fas/emitted-event-stream-seam, commits49a19bf/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
Documentation