Skip to content

fix(ui): the drawer's views flicker in halfway down the panel inside an embed - #312

Merged
Ardnived merged 2 commits into
mainfrom
fix/embed-transition-flicker
Oct 20, 2026
Merged

Ardnived merged 2 commits into
mainfrom
fix/embed-transition-flicker

Conversation

@Ardnived

@Ardnived Ardnived commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes the drawer flicker in embeds: during each navigation the incoming view no longer lands halfway down the panel before jumping to the top
  • Each transition also stops writing a temporary <style> into the host page's <head>

Reported on the WordPress embed at shrimataji.org/…/?atlas=/br/distrito-federal. It is a regression from the move into the shadow root (#236) and hits every embed. sahajatlas.com was unaffected, since it has no shadow root.

Change outline

Components — the drawer's view cross-fade

AnimatePresence mode="popLayout" takes the outgoing view out of flow by appending a <style> to document.head. In an embed that is the host's head, and it cannot style elements inside the widget's shadow root. So nothing was popped: both views shared the sheet's flex column for the whole fade. Each took half the panel, and the new one sat in the lower half.

 DrawerContent                                        src/views/DrawerStack/DrawerStack.tsx
-  AnimatePresence mode="popLayout"
-    motion.div key=top.path  "flex min-h-0 flex-1 flex-col"   # in flow; relies on the head <style>
+  div "relative min-h-0 flex-1"
+    AnimatePresence                                  # default sync mode
+      ViewLayer key=top.path                         src/views/DrawerStack/ViewLayer.tsx
+        motion.div "absolute inset-0 flex flex-col"  # both views overlap; no stylesheet
+          exiting → aria-hidden, pointer-events-none
         Suspense › ResetErrorBoundary › TopView

Behaviour — a lint rule

 eslint.config.js
+  src/**/*.tsx (shipped code): no-restricted-syntax refuses the literal "popLayout"

Neither layout nor the host's <head> is visible to jsdom, so a lint rule is what stops popLayout from coming back.

Preview

⚠ This standalone preview has no shadow root, so it never showed the flicker. I re-ran the trace with this preview served in place of sahajatlas.com on the tester's live page. Mid-fade, both views were at 1px, and the host's <head> stayed at 31 styles. Any embed host can run the same check with SahajAtlasWordpress's browser lane and SAHAJ_ATLAS_WIDGET_FROM=https://pr-312-sahajatlas.contact-c66.workers.dev.

Contract impact

Hosts no longer get a framer-motion <style> in their <head> while the drawer changes view. That injection was never documented, and it is what docs/embedding.md already says the widget does not do. The entry is in CHANGELOG.md, and no snippet, origin or CSP row changes.

Test results

  • Lean gate (lint + typecheck + test:run) ✓, with 148 files and 1755 tests, and 3 consecutive full-lane runs green
  • ViewLayer.test.tsx, in jsdom inside a shadow root:
    • both layers are absolute and overlap;
    • the outgoing layer is aria-hidden and pointer-events-none mid-fade;
    • each assertion fails with its half of the fix removed.
  • The lint rule fires on mode="popLayout" in DrawerStack.tsx.
  • pnpm size ✓: embed 312.4 / 318 KiB.

Manual verification

Measured on the tester's page in Chromium at 1280px, sampling every frame for 700ms after a real mouse click:

top of each view within the panel, mid-fade host <head> styles mid-fade
production outgoing at 1px, incoming at 344px (panel 688px) 31 → 32
this branch outgoing at 1px (aria-hidden), incoming at 1px 31, unchanged

Notes for reviewer

  • The page scrolling down to the flickered position did not reproduce. I tried Chromium and WebKit, a slow network, several scroll offsets, and real mouse clicks, and the host's scrollY and every scroll offset inside the widget held still. Nothing in our source or bundle scrolls the page. The scroll reportedly aligns to the position the new view flickered to, which no longer exists after this fix. If the report comes back, the browser and the exact clicks are what's needed.
  • Possible follow-up, unconfirmed in real Safari: in Playwright's WebKit, a mouse click on a panel link in the embed fired no click event, while the same click on sahajatlas.com did. A minimal page showed WebKit drops click when pointer capture is set on another element during pointerdown. Worth checking in real Safari before filing.
Detail
  • Hand-rolled instead of upgraded: framer-motion 14 adds a root prop that would put the <style> inside the shadow root. That is a three-major upgrade that still installs a <style> element, so I overlapped the layers absolutely instead.
  • Sync mode is safe: every Drawer variant has a definite height (inset-y-0, h-[var(--sy-frame-h)], or filled), so absolutely positioned layers inside a flex-1 wrapper size exactly as the in-flow view did.
  • The spec stubs requestAnimationFrame in vi.hoisted. framer-motion reads it when it loads, so per-test fake timers never reached it, and under the loaded lane the 150ms exit sometimes finished before the assertions ran.

🤖 Generated with Claude Code

Ardnived and others added 2 commits October 19, 2026 17:51
Reported on a WordPress embed: navigating, the panel's content flickered in halfway down,
then jumped to the top. `AnimatePresence mode="popLayout"` pops the outgoing view out of
flow with a `<style>` framer-motion appends to `document.head` — the host's head, which
cannot reach into the widget's shadow root (#236). So in every embed both views stayed in
the flex column for the whole fade, each taking half the panel, and each transition left a
`<style>` in the host's <head> for its duration. Measured on the live page: the incoming
view at 344px of a 688px panel, the host's head 31 → 32 styles mid-fade.

`ViewLayer` fills the sheet absolutely, so the two views overlap for the fade and need no
stylesheet. The outgoing layer also drops pointer events and leaves the accessibility tree
the moment it starts to exit. A lint rule refuses `popLayout` in shipped code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0975c5a
Status: ✅  Deploy successful!
Preview URL: https://71a741b2.sahajatlas.pages.dev
Branch Preview URL: https://fix-embed-transition-flicker.sahajatlas.pages.dev

View logs

@Ardnived
Ardnived merged commit 363ee50 into main Oct 20, 2026
11 checks passed
@Ardnived
Ardnived deleted the fix/embed-transition-flicker branch October 20, 2026 01:03
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Oct 20, 2026
sydevs-bot pushed a commit that referenced this pull request Oct 26, 2026
… layer

The ticket's 25px float is real, and an isolated harness cannot see it.
Measured on this PR's own deployed preview at 390x844: the bar's bottom
edge sat at 818.69 against an 844 viewport, with the panel's own content
showing through the 25.31px strip underneath -- exactly as reported.

The cause is the containing block, not the arithmetic. `bottom:
var(--sy-sheet-top)` cancels vaul's translate only while it is measured
from the sheet's own bottom edge. `absolute` resolves against the nearest
POSITIONED ancestor, and since #312 the view crossfade puts two of them
between the sheet and the view: `relative min-h-0 flex-1` and `absolute
inset-0 flex flex-col`, both filling the sheet's CONTENT box, which its
`pb-[calc(var(--sy-frame-h)*0.03)]` ends 25.32px above its border box.
Walked on the preview: footer 668.69-818.69, crossfade layer 564-1362.69,
sheet 544-1388.

`fixed` resolves against the nearest ancestor with a transform instead,
and that is the sheet -- vaul writes `translate3d` on it and
`will-change: transform` with it. So the offset is measured from the box
it was always meant to be measured from, whatever DrawerStack nests in
between, and the 3% never has to be named. Subtracting the 3% instead
would have been correct only for the current nesting, and 25px too low
for a view that composes its footer directly under DrawerContent.

⚠ I reported this symptom as not reproducing, in the first commit on this
branch and in the PR body. That was wrong, and the way it was wrong is
the useful part: the Ladle probe I measured in composes `DrawerFooter`
straight under `DrawerContent`, so it had no crossfade layer to resolve
against and the bar measured flush. Both docblocks and the spec now carry
the correction, and the spec says why an isolated harness is not evidence
here.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SHjmUonsTYZg2xiQ7e7yqY
sydevs-bot pushed a commit that referenced this pull request Oct 26, 2026
`parentElement` was bound to `sheet`, 20 lines under a docblock saying the
view crossfade (#312) sits between the sheet and the footer. Both cannot
be true, and the next author reasons from the mechanism: the parent is the
crossfade layer, so the name is `layer`.

Publishing per layer is the right scope, and that is now stated rather
than implied. On the sheet, one value would be shared by both crossfade
layers, and the outgoing layer's cleanup would blank the incoming
footer's value mid-fade.

The contract it buys was unstated and is the part a later composition can
break: a `sticky` footer's parent must also contain the body it clears.
Anywhere it does not, the clearance resolves to its `0px` fallback and
the content ends under the bar, with nothing failing.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0198xNcXbYVmd5prap54yrHB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant