Skip to content

refactor(docs,storybook): adopt the layer-docs Storybook bridge (UXF-278) - #337

Open
alexgrozav wants to merge 2 commits into
mainfrom
agent/palette/UXF-278-storybook-bridge
Open

alexgrozav wants to merge 2 commits into
mainfrom
agent/palette/UXF-278-storybook-bridge

Conversation

@alexgrozav

@alexgrozav alexgrozav commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

apps/docs and apps/storybook each held one half of a hand-rolled postMessage contract — theme sync, height measurement, manager chrome accounting. Both halves now ship in @uxfront/layer-docs 0.4.1, which apps/docs already depends on since #335. This replaces the local copies with the shared ones.

Two commits, in the order they can be deployed:

1. apps/storybook — the bridge. .storybook/preview.ts and .storybook/manager.ts call installDocsEmbedPreviewBridge / installDocsEmbedManagerBridge. The addon-specific work (the @vueless/storybook-dark-mode channel, the sb-addon-themes-3 store, addons.setConfig) stays local, reached through the bridges' onTheme callback. legacyNamespace: "styleframe" keeps the existing styleframe:* message names alive alongside the neutral ones, so this deploys before the docs side without breaking the embeds already in production.

2. apps/docs — the content. StoryPreview.vue is deleted; 385 ::story-preview blocks across 65 files become ::storybook-embed. storybookBaseUrl and storybookLegacyMessageNamespace are set in runtimeConfig.public.

The panel → mode mapping

mode names the Storybook surface rather than describing one of two, so the rename is not one-to-one. The mapping preserves today's rendering exactly:

Before After URL
panel: true (292) mode: panel manager with the addon panel
panel: false (1) mode: full manager, full=1
no panel (92) mode: full manager, full=1 — the old default, now explicit

Reserved heights are unchanged (320 for full, 600 for panel), so the embeds still hold their space before Storybook reports a real one.

mode: preview — the layer's own default, embedding iframe.html with no Storybook chrome — is a lighter surface than full and worth considering for the 92. It is a design decision rather than a rename, so it is left out of this PR.

Dependency note

@uxfront/layer-docs is added to apps/storybook as a devDependency for the framework-free /storybook subpath. It adds no new packages to the store — the lockfile grows by 42 peer-resolution snapshots of packages the workspace already installs.

⚠️ Contributor action — local Storybook URL

StoryPreview.vue hardcoded import.meta.dev ? http://localhost:6006 : <deployed>. StorybookEmbed reads storybookBaseUrl from runtimeConfig.public instead, which points at the deployed Storybook in every environment. Local development against a local Storybook now needs an explicit override:

NUXT_PUBLIC_STORYBOOK_BASE_URL=http://localhost:6006

apps/docs/.env.example carries this line. A contributor with an existing apps/docs/.env does not get it automatically: their embeds silently load the deployed Storybook instead of their local one. Copy the line into your .env after you pull this change.

Related issue

Relates to UXF-278. Follows #335, which had to land first because both touch apps/docs.

Type of change

  • 🐞 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📖 Documentation
  • ♻️ Refactor / internal (no functional change)
  • 🔧 Build / tooling / CI

Checklist

  • My commits follow Conventional Commits with a package scope (e.g. feat(theme): …)
  • I ran pnpm build:nodocs && pnpm lint && pnpm typecheck && pnpm test and everything passes
  • I added a changeset (pnpm changeset) for changes to publishable packages, or this change only touches docs/storybook/app/playground/tests
  • I added or updated tests where relevant
  • I updated documentation where relevant
  • I did not edit generated files (dist/, .styleframe/)
  • My PR targets main and stays focused in scope

Notes on the checklist: no changeset — this touches only apps/docs and apps/storybook, matching #335. No new tests — the rewrite adds no behaviour, and the bridge's own logic is tested in the layer (storybook/index.test.ts, app/utils/storybookEmbed.test.ts). apps/docs/AGENTS.md is updated with the new block syntax and what each mode means. Repo-wide pnpm lint ran out of memory in my environment; oxlint on the changed files and pnpm format:check across all 1826 files both pass.

Notes / screenshots

Verified in a browser against apps/storybook on :6006 and apps/docs on :3000, on /docs/theme/components/button (12 embeds, both modes). Console: 0 errors.

  • Loads — mode: panel builds the panel URL, mode: full appends full=1. No .story-preview left in the DOM.
  • Auto-height — the panel embed resized from its reserved 600px to a reported 443px; the full all-variants embed from 320px to 886px. That signal crosses preview → manager → docs page, so it exercises both new bridges end to end.
  • Theme sync — toggling the docs header to dark flipped the manager chrome and the story canvas, confirming the theme leg through legacyNamespace.
  • A11y — every embed iframe now carries a title (Storybook preview: theme recipes actions button default); the old StoryPreview left the frame unlabelled for screen readers.

Both builds pass: pnpm --filter @styleframe/storybook build and pnpm --filter @styleframe/docs build.

Screenshots (panel embed light/dark, and a full-mode embed) are attached to the issue thread.

…er one (UXF-278)

`apps/storybook` hand-rolled both halves of the docs-embed postMessage
contract — theme relay, height measurement, chrome accounting. The docs
side of that contract now ships in `@uxfront/layer-docs/storybook`, so
the local copy is a fork that can only drift.

`legacyNamespace: "styleframe"` keeps the existing `styleframe:*` message
names alive alongside the neutral ones, so this deploys before the docs
rewrite without breaking the embeds already in production.

The layer is framework-free on this subpath and adds no new packages to
the store — only peer-resolution snapshots of packages the workspace
already installs.
`StoryPreview` was the docs half of a postMessage contract `apps/storybook`
implemented on the other side. `StorybookEmbed` in `@uxfront/layer-docs`
is that same component, maintained once for every consumer, so the local
one is deleted rather than kept in parallel.

`panel` becomes `mode`, which names the Storybook surface instead of
describing one of two. The mapping preserves today's rendering exactly:
`panel: true` was the manager with its addon panel (`mode: panel`), and
both `panel: false` and an absent `panel` built the manager's `full=1`
URL (`mode: full`). The 92 blocks that relied on that default now say so.

`mode: preview` — the layer's own default, embedding `iframe.html` with
no Storybook chrome — is a lighter surface than `full` and worth a look,
but changing 92 embeds is a design decision, not a rename.

The reserved heights are unchanged (320 for `full`, 600 for `panel`), so
the embeds still reserve their space before Storybook reports a real one.
@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 309f2ab

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
styleframe-dev Ready Ready Preview Sep 8, 2026 7:14am UTC
styleframe-dev-storybook Ready Ready Preview Sep 8, 2026 7:14am UTC

Request Review

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch was successfully deployed

2 active deployments
Preview – styleframe-dev — 309f2ab9 Deployed Sep 8, 2026 by vercel[bot]
Preview – styleframe-dev-storybook — 309f2ab9 Deployed Sep 8, 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