Skip to content

feat(sanity-plugin-markdown): migrate styling to vanilla-extract - #1844

Open
stipsan wants to merge 4 commits into
mainfrom
cursor/migrate-markdown-vanilla-extract-dd27
Open

feat(sanity-plugin-markdown): migrate styling to vanilla-extract#1844
stipsan wants to merge 4 commits into
mainfrom
cursor/migrate-markdown-vanilla-extract-dd27

Conversation

@stipsan

@stipsan stipsan commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

Migrates sanity-plugin-markdown off styled-components to vanilla-extract (zero-runtime CSS), following the monorepo migration skill.

Changes

  • Replaced styled(Box) EasyMDE/CodeMirror theme overrides with colocated MarkdownInput.css.ts using globalStyle() scoped under a local wrapper class
  • Bridges Studio theme tokens via createVar() + assignInlineVars() + useTheme_v2() (color.fg / border / bg / selectable.primary.hovered.bg)
  • Switched tsdown to vanillaExtract: true; registered vanillaExtractPlugin() in Vitest
  • Removed styled-components peer dependency (kept as devDependency for @sanity/ui peer alignment)
  • Added ./bundle.css export (auto-synced by tsdown) and package-exports snapshot update
  • Kept sanity-plugin-markdown/next CSS-import-free (strips auto-injected bundle.css from dist/next.js); README documents importing bundle.css from _app.tsx alongside easymde
  • Patch changeset included

Verification

  • pnpm format / pnpm lint / pnpm knip
  • pnpm build --filter=sanity-plugin-markdown emits dist/bundle.css; dist/index.js imports it; dist/next.js does not
  • Package-exports snapshot updated
  • Visual fidelity checked in test studio (edit + side-by-side preview)
  • Review threads addressed (style merge + /next CSS regression)

Edit mode:

Markdown editor edit mode

Side-by-side preview:

Markdown editor side-by-side preview

Note

With unstable_bundledDev: true (test-studio default), lazy-loading react-simplemde-editor currently fails under Vite 8/rolldown (__toCommonJS / Cannot convert undefined or null to object). Confirmed the same failure on the pre-migration styled-components component — not introduced by this PR. Visual check was done with bundledDev temporarily disabled for that session only.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Replace styled-components EasyMDE theme overrides with colocated
vanilla-extract styles, bridging Studio theme tokens via CSS variables.
@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 996745c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sanity-plugin-markdown Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
plugins-studio Ready Ready Preview Aug 6, 2026 9:05am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
plugins-e2e-test-studio Ignored Ignored Aug 6, 2026 9:05am

Request Review

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

✅ E2E Tests

🟢 24 passed🟡 2 flakyview full reportview run

Studio: https://plugins-e2e-test-studio-26fmwissd.sanity.dev

Datasets: pr-1844-chromium-31087593087, pr-1844-firefox-31087593087

@socket-security

socket-security Bot commented Aug 6, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 32.01% 5507 / 17201
🔵 Statements 31.78% 5811 / 18280
🔵 Functions 27.82% 1427 / 5128
🔵 Branches 23.33% 2828 / 12120
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
plugins/sanity-plugin-markdown/src/components/MarkdownInput.css.ts 0% 0% 0% 0%
plugins/sanity-plugin-markdown/src/components/MarkdownInput.tsx 7.89% 0% 0% 9.09% 26-51, 90-170
Generated in workflow #8787 for commit 996745c by the Vitest Coverage Report Action

@stipsan
stipsan marked this pull request as ready for review August 6, 2026 08:43
@stipsan
stipsan requested a review from a team as a code owner August 6, 2026 08:43
@stipsan
stipsan requested review from Copilot and pedrobonamin and removed request for a team August 6, 2026 08:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates sanity-plugin-markdown styling from styled-components to vanilla-extract to align with the monorepo’s zero-runtime CSS approach, including theme-token bridging and CSS bundle export wiring.

Changes:

  • Replaced styled(Box)-based editor overrides with MarkdownInput.css.ts (globalStyle) scoped under a wrapper class and theme variables via createVar() + assignInlineVars() + useTheme_v2().
  • Enabled vanilla-extract in build + tests (tsdown vanillaExtract: true, Vitest vanillaExtractPlugin() + runtime-style disabling).
  • Added ./bundle.css package export and updated the package-exports snapshot + changeset.

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pnpm-lock.yaml Lockfile updates for added vanilla-extract deps and related workspace resolution changes.
plugins/sanity-plugin-markdown/vitest.config.ts Registers vanilla-extract Vite plugin for Vitest and disables runtime CSS injection in tests.
plugins/sanity-plugin-markdown/tsdown.config.ts Switches build pipeline from styled-components mode to vanillaExtract: true.
plugins/sanity-plugin-markdown/tsconfig.json Simplifies include after removing the styled-components theme typing shim.
plugins/sanity-plugin-markdown/src/typings.d.ts Removes styled-components theme augmentation no longer needed post-migration.
plugins/sanity-plugin-markdown/src/index.test.ts Updates exports snapshot to include ./bundle.css.
plugins/sanity-plugin-markdown/src/components/MarkdownInput.tsx Replaces styled wrapper with vanilla-extract wrapper + theme variable assignment.
plugins/sanity-plugin-markdown/src/components/MarkdownInput.css.ts Adds scoped global editor/theme override rules via vanilla-extract.
plugins/sanity-plugin-markdown/package.json Adds ./bundle.css export and vanilla-extract dependencies; removes styled-components from peers.
.changeset/markdown-vanilla-extract.md Patch changeset documenting the migration.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/sanity-plugin-markdown/src/components/MarkdownInput.tsx Outdated
Comment thread plugins/sanity-plugin-markdown/src/components/MarkdownInput.tsx
Strip the auto-injected bundle.css import from the next entry so Next.js
pages consumers can keep importing CSS from _app, and merge caller style
with assignInlineVars so inline styles are not discarded.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Suppressed comments (2)

plugins/sanity-plugin-markdown/tsdown.config.ts:15

  • The /next entry relies on a string replace to remove the injected bundle.css import. The current regex only matches when the import is the very first line and uses \n, so it may fail if tsdown ever reorders imports or emits CRLF line endings, leaving /next non–CSS-import-free.
  generateBundle(_options, bundle) {
    const chunk = bundle['next.js']
    if (chunk?.type !== 'chunk') return
    chunk.code = chunk.code.replace(/^import ["']sanity-plugin-markdown\/bundle\.css["'];\n/, '')
  },

plugins/sanity-plugin-markdown/src/index.test.ts:24

  • This PR introduces a custom tsdown plugin to ensure dist/next.js is CSS-import-free. The existing test only snapshots the package exports manifest; it doesn’t assert the key behavioral requirement that dist/index.js imports bundle.css while dist/next.js does not. Adding a small dist-output assertion would guard against regressions in the strip logic.
      "./bundle.css": {},
      "./next": {
        "MarkdownInput": "function",
        "defaultMdeTools": "object",
        "markdownSchema": "function",

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 00479cf. Configure here.

Comment thread pnpm-lock.yaml Outdated
Add react-dom and @types/react-dom so the workspace's sanity peer
variant matches other @sanity/ui consumers in the lockfile.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Suppressed comments (2)

plugins/sanity-plugin-markdown/src/components/MarkdownInput.tsx:45

  • useTheme_v2().color.selectable was previously treated as optional; accessing color.selectable.primary.hovered.bg without optional chaining can throw at runtime if selectable is undefined. Use optional chaining with a safe fallback (eg color.bg) when assigning the CSS var.
          [fgVar]: color.fg,
          [borderVar]: color.border,
          [bgVar]: color.bg,
          [selectionHoveredBgVar]: color.selectable.primary.hovered.bg,
        }),

plugins/sanity-plugin-markdown/src/index.test.ts:22

  • The build behavior that /next must remain CSS-import-free (by stripping the auto-injected bundle.css import) is new but currently untested. Add a regression assertion against dist/next.js so accidental reintroduction of the CSS import is caught.
        "markdownSchemaType": "object",
      },
      "./bundle.css": {},
      "./next": {
        "MarkdownInput": "function",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants