DEV Community

Jack Song
Jack Song

Posted on

4 Zero-Build Browser UX Fixes: Split Credit Wallets, Lazy Audio Mutexes, Grid Overlays & Top-Layer Dialogs

Calendrier Avent en Ligne — interactive French online Advent calendar

When you ship a zero-framework browser utility that runs without accounts or forced email capture, the bugs that actually hurt conversion are rarely dramatic crashes. They are small, quiet friction points: a modal overlay clipping its bottom button on a 375px phone screen, a multi-second loading spinner before telling a guest they have zero paid credits, or two <audio> players accidentally singing over each other.

While upgrading Calendrier Avent en Ligne—a free French-first interactive online Advent calendar supporting personal gift boxes and collaborative Entre amis countdowns—we audited every mobile and desktop interaction and fixed four concrete browser patterns in plain HTML, CSS, and vanilla JS.

Here are the exact bugs we hit and the zero-dependency patterns we shipped to solve them (with reusable helpers published in our MIT repo advent-ics-midnight-js).


1. Never Make a Zero-Balance Guest Wait 4 Seconds for a 401

One subtle architectural trap in browser tools with both free earned credits (stored locally in localStorage for cosmetic themes) and optional purchased credits (stored server-side for heavier AI features like a 24-door idea generator or a custom French Christmas song) is hiding the distinction behind a single balance badge.

We originally rendered one combined ❄️ 2 pill in the header. A visitor with 2 free welcome credits would click an AI tool costing 5 purchased credits, watch a progress bar animate for 3–5 seconds, and only then get an error from the server.

Two small changes eliminated that dead end completely:

  1. Always split the two wallets in the UI (Flocons gratuits vs. Flocons achetés) so visitors immediately understand which balance unlocks cosmetic door wraps (2–4 ❄️) versus server-side AI features (5 ❄️ / 15 ❄️).
  2. Pre-check meLoaded && paidCredits < cost synchronously before firing fetch(), while keeping a clean one-click free fallback right inside the upsell panel:
function canStartPaidAction({ meLoaded, paidCredits, cost }) {
  if (!meLoaded) {
    // Session state not hydrated yet; defer to server validation.
    return { allowed: true, reason: "pending_hydration" };
  }
  if (Number(paidCredits) < Number(cost)) {
    return {
      allowed: false,
      reason: "not_enough_credits",
      missing: Math.max(0, Number(cost) - Number(paidCredits)),
    };
  }
  return { allowed: true, reason: "ok" };
}
⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด ⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด

We applied the same friction-removal principle to optional paid door wraps on Calendrier Avent en Ligne: if a creator experiments with a 4 ❄️ luxury wrap on Door 1 while holding 2 ❄️ and clicks Create, the modal shows both the top-up packs and a one-click "Create for free without paid wraps" button that resets paid wraps to standard paper (0 ❄️) and submits the form automatically. Zero trapped drafts.


2. Lazy-Loading Real <audio> Previews With a 6-Line Playback Mutex

Adding a real sung MP3 sample dramatically improves trust compared to describing an AI song in text, especially when the demo appears in three different surfaces (the inline door editor, the standalone song dialog, and the post-creation spotlight card).

However, embedding three <audio> tags carelessly causes two immediate regressions:

  • Browsers eagerly download megabytes of MP3 metadata on initial page load, hurting mobile LCP.
  • Visitors who play the sample inside the page and then open a modal sample hear two tracks overlapping.

Pairing loading="lazy" with preload="none" and controls keeps initial transfer at 0 bytes until the visitor explicitly presses Play, and a single delegated capturing play listener coordinates every <audio> element inside the tool root:

<figure class="adv-demo-audio">
  <figcaption>Real French sample</figcaption>
  <audio controls loading="lazy" preload="none" src="/_a/demo-chanson-noel.4a2cf092ce.mp3"></audio>
</figure>
⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด ⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด
// Capture phase is required because HTMLMediaElement "play" does not bubble.
root.addEventListener("play", (event) => {
  if (!event.target || event.target.tagName !== "AUDIO") return;
  root.querySelectorAll("audio").forEach((audioEl) => {
    if (audioEl !== event.target) {
      try { audioEl.pause(); } catch (_) {}
    }
  });
}, true);
⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด ⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด

Notice the third argument true (useCapture): HTMLMediaElement's play event does not bubble, so a normal bubbling listener on root will silently never fire!


3. Fixing Mobile Overlay Clipping Without Fixed Heights or order Hacks

On narrow mobile viewports (375×812), an overflow: hidden stage container with a fixed 224px canvas and a position: absolute; inset: 0; justify-content: center; end-screen overlay is a classic clipping bug: as soon as the end-screen displays a score, reward pill, primary CTA, and two share buttons (~310px tall), justify-content: center pushes the top heading and bottom button right past the clipped edges.

Replacing position: absolute with a shared CSS Grid cell (grid-area: 1 / 1) plus min-block-size and justify-content: safe center solves both idle compactness and dynamic end-screen height in 10 lines of CSS:

.stage-board {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-block-size: 224px;
  overflow: hidden;
}

.stage-canvas,
.stage-overlay {
  grid-area: 1 / 1;
}

.stage-overlay {
  position: relative;
  width: 100%;
  min-block-size: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  z-index: 4;
}
⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด ⭐ Must Read: jack song bcbd/ zero build browser ux fixes split credit wallets lazy audio mutexes grid overlays top layer ji - สรุปดราม่าล่าสุด

When the idle overlay is shorter than 224px, the board stays compact so the primary Start button remains above the fold. When the end-screen expands to 368px, the shared grid track grows naturally with zero top/bottom clipping—and safe center prevents scroll-inaccessible top overflow on extra-narrow viewports.

Similarly, when making mobile forms easier to reach on Calendrier Avent en Ligne, we resisted using CSS order: -1 to visually flip the form above the calendar grid—because CSS order decouples visual order from DOM/keyboard Tab focus order. Instead, we kept natural DOM order, added a compact mobile quick-jump CTA bar above the grid, and folded the empty collaborative preview to 2 rows (8 doors) on narrow screens.


4. Opaque Top-Layer <dialog> Polish & Honest Copy

Native HTML <dialog> with closedby="any" and discrete @starting-style transitions removes the need for heavy modal libraries, but two small details showed up during live mobile QA:

  1. Explicitly style non-transparent surfaces on dialog:not(.fullscreen-stage): leaving background inheritance ambiguous caused subtle visual bleed on dark backdrops, whereas explicit background: #FFFFFF; max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain; with a crisp 0.16s transition feels native on both iOS Safari and Android Chrome.
  2. Keep every UI promise 100% accurate: we caught a micro-copy line claiming doors were "editable after creation" when our zero-account #owner= architecture actually lets creators edit freely before creation and moderate/preview/delete after creation. Tightening that wording across the studio, our 24 French Advent calendar ideas guide, our team & HR guide, and our objective 8-tool 2026 comparison keeps user expectations aligned with real behavior.

Try It Live or Reuse the Snippets

If you want to inspect these patterns in action—especially the mobile layout, split credit wallet, lazy <audio> sample, and zero-account workflow—you can test Calendrier Avent en Ligne directly in Chrome, Safari, or Firefox (no signup required), or grab the standalone date-unlock, RFC 5545 .ics, and wallet/audio helpers from sunrain113/advent-ics-midnight-js.

Top comments (0)