fix(blocks): keep the "." shortcut out of fields inside a shadow root

GU
2d ago
+26-2

What

On a page that isn't framed, StudioBridge turns "." into the "open in Studio" shortcut (editShortcut), and skips it while the visitor types in a field by checking e.target. A keydown from a field inside a shadow root reaches the document retargeted to the shadow host (a plain element), so the check misses it.

Reported on v7 (LiveControls, fixed in #783): a store embeds a third-party widget whose modal lives in an open shadow root and asks for an email; typing the "." of the email navigated the shopper to studio.decocms.com/choose-editor. v8's bridge carried the same check over.

Fix

Read the field from e.composedPath()[0] (falls back to e.target). For an open shadow root the composed path starts at the real input. A closed shadow root still hides its fields.

Verification

  • New test in preview.test.tsx: a "." typed into an input inside an open shadow root isn't prevented, while Ctrl+"." on the host itself still opens the chooser. It fails without the fix and passes with it.
  • bunx vitest run packages/blocks/src/v8/preview/preview.test.tsx → 34 passed; bun run typecheck in packages/blocks and biome check on the changed files pass.

šŸ¤– Generated with Claude Code


Summary by cubic

Fixes the "." editor shortcut so typing inside a field within a shadow root (a third-party widget's form) no longer checks out of the field or navigates shoppers to Studio's editor chooser.

Keydown events from fields inside a shadow root reach the document retargeted to the shadow host, so StudioBridge's check for INPUT/TEXTAREA/SELECT missed them and treated the "." as the shortcut. The bridge now reads the field from the event's composed path, falling back to e.target. Closed shadow roots still hide their fields.