Skip to content

fix(playground): wait for Ionic before reading the mode in the JavaScript example - #4931

Open
brandyscarney wants to merge 1 commit into
mainfrom
fix/config-mode-javascript-stackblitz
Open

brandyscarney wants to merge 1 commit into
mainfrom
fix/config-mode-javascript-stackblitz

Conversation

@brandyscarney

Copy link
Copy Markdown
Member

Fixes the JavaScript example for Accessing the Mode when it's opened in StackBlitz. The button rendered empty and the console showed Uncaught TypeError: window.Ionic.config.get is not a function.

The example's inline <script> runs while the page is parsed, before StackBlitz's index.ts loads Ionic. At that point window.Ionic.config is still the plain object the playground puts in <head> ({ mode: 'ios' } or {}), which has no get method. The docs page itself works because its demo.html runs the same code in a module script after Ionic loads.

The example now waits for customElements.whenDefined('ion-button'), by which point Ionic has replaced window.Ionic.config with the real config. The || document.documentElement.getAttribute('mode') || 'md' fallbacks are dropped, since config.get('mode') always returns the resolved mode once Ionic has loaded. The v7, v8 and v9 examples were identical and all get the fix.

Tested by building the StackBlitz HTML project locally with the playground's <head> config and loading it in Chromium, on @ionic/core 9.0.15 and 8.8.21:

Example Config Before After
v9 / v8 { mode: 'ios' } empty button, TypeError Current mode: ios, secondary, outline
v9 / v8 {} empty button, TypeError Current mode: md, tertiary, solid

Accessing the Mode preview

@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-docs Ready Ready Preview Dec 2, 2026 11:13pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 1e06ff30 Deployed Dec 2, 2026 by vercel[bot]
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