Skip to content

fix(ui): move Comments/CommentForm to emdash/ui/comments subpath (#2039)#2044

Open
scottbuscemi wants to merge 1 commit into
mainfrom
fix/2039-comments-ui-subpath
Open

fix(ui): move Comments/CommentForm to emdash/ui/comments subpath (#2039)#2044
scottbuscemi wants to merge 1 commit into
mainfrom
fix/2039-comments-ui-subpath

Conversation

@scottbuscemi

Copy link
Copy Markdown
Collaborator

What does this PR do?

Moves the Comments and CommentForm components out of the emdash/ui barrel into a dedicated emdash/ui/comments entry point, so their CSS no longer bleeds onto pages that don't render comments.

Astro's CSS scanner processes the entire barrel module when any export is imported. Because Comments.astro and CommentForm.astro were re-exported from emdash/ui's barrel (src/components/index.tssrc/ui.ts), a page that only did import { PortableText } from "emdash/ui" pulled their <style> blocks into a shared, render-blocking CSS chunk on every page — even the homepage. This mirrors the existing emdash/ui/search entry point, which already keeps LiveSearch's CSS isolated for the same reason.

Closes #2039

Reproduction / verification

Built demos/simple (astro build, SSR) before and after the change and grepped the emitted client CSS for ec-comment selectors:

CSS file (loaded on…) Before (barrel) After (this PR)
Base.*.css (shared layout — every page) 1 0
index.*.css (home) 0 0
styles.*.css (global) 0 0
_slug_.*.css (posts page that renders comments) 1 1

Comment CSS is now confined to the page that actually imports the components.

Migration

-import { Comments, CommentForm } from "emdash/ui";
+import { Comments, CommentForm } from "emdash/ui/comments";

All in-repo demos, templates, fixtures, e2e/integration fixtures, docs, and skills were updated. A changeset (minor) documents the move for external consumers.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (packages, demos, templates)
  • pnpm lint passes (0 diagnostics)
  • pnpm test passes (core suite: 4721 passed)
  • pnpm format has been run
  • I have added/updated tests for my changes (verified via a before/after production build CSS comparison — see above)
  • User-visible strings in the admin UI are wrapped for translation — n/a (no admin UI strings changed)
  • I have added a changeset
  • New features link to an approved Discussion — n/a (bug fix)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.8 (opencode)

Screenshots / test output

See the before/after CSS table above: ec-comment selectors dropped from the shared Base.*.css (loaded on every page) to only the posts page chunk that renders comments.

Their <style> blocks were pulled into a shared, render-blocking CSS chunk
on every page that imported anything from the emdash/ui barrel (e.g.
PortableText), because Astro scans the whole barrel module graph. Splitting
them into a dedicated entry point keeps comment CSS off pages that don't
render comments, mirroring the existing emdash/ui/search entry point.
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 375bce7

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

This PR includes changesets to release 16 packages
Name Type
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Minor
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds 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

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR touches 25 files. PRs with a broad scope are harder to review. Please confirm the scope hasn't drifted beyond the intended change.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@2044

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@2044

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@2044

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@2044

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@2044

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@2044

emdash

npm i https://pkg.pr.new/emdash@2044

create-emdash

npm i https://pkg.pr.new/create-emdash@2044

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@2044

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2044

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2044

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2044

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2044

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2044

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@2044

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@2044

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@2044

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@2044

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@2044

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@2044

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2044

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@2044

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@2044

commit: 375bce7

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 375bce7 Jul 15 2026, 01:27 AM

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 375bce7 Jul 15 2026, 01:27 AM

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do 375bce7 Jul 15 2026, 01:31 AM

@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Jul 15, 2026

@emdashbot emdashbot Bot 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.

The approach is correct: moving Comments and CommentForm out of the emdash/ui barrel into emdash/ui/comments is the right fix for the Astro CSS-scanning issue described in #2039, and it mirrors the existing emdash/ui/search entry point. The export map, barrel cleanup, tsconfig exclusion, changeset, and in-repo fixture/demo/template .astro updates are all consistent.

I checked the diff, the changed core files, and searched the tree for remaining Comments/CommentForm imports from emdash/ui. I found one real gap: the canonical skills/building-emdash-site/ docs were updated, but the copies embedded in every template under templates/*/.agents/skills/building-emdash-site/ still instruct users to import comments from the old emdash/ui barrel. Since those copies are tracked files with no sync script, they are now stale and will break (or mislead) anyone scaffolding a site from a template.

I also noted that, while the integration/e2e fixtures now exercise emdash/ui/comments implicitly, there is no automated regression guard for the actual CSS-isolation claim. Given the difficulty of asserting over Astro's emitted CSS, this is a suggestion rather than a blocker.

Conclusion: the fix is sound, but the stale template skill copies need to be updated before merge.


Findings

  • [needs fixing] templates/blank/.agents/skills/building-emdash-site/SKILL.md:102-111

    The canonical skills/building-emdash-site/SKILL.md was updated to import Comments/CommentForm from emdash/ui/comments, but the embedded copy inside every template still shows the old barrel import.

    import {
    	PortableText,
    	Image,
    	WidgetArea,
    	EmDashHead,
    	EmDashBodyStart,
    	EmDashBodyEnd,
    } from "emdash/ui";
    import { Comments, CommentForm } from "emdash/ui/comments";
    import LiveSearch from "emdash/ui/search";
    

    The same stale example exists in templates/blank/.agents/skills/building-emdash-site/references/site-features.md (line 291) and in the corresponding building-emdash-site copies under templates/blog/, templates/blog-cloudflare/, templates/marketing/, templates/marketing-cloudflare/, templates/portfolio/, templates/portfolio-cloudflare/, templates/starter/, and templates/starter-cloudflare/. Those are real tracked files (not symlinks or generated artifacts), so they need the same update.

  • [suggestion] packages/core/src/components/index.ts:25-26

    The structural fix is clear from this comment, but there is no automated guard against someone re-adding Comments/CommentForm to this barrel in the future. The PR's verification is a manual build comparison; consider adding a regression check (e.g., a build test that greps emitted CSS for ec-comment selectors on a page that does not import emdash/ui/comments, or a static check that components/index.ts does not re-export the comment components).

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Jul 15, 2026

@khoinguyenpham04 khoinguyenpham04 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing this, the approach looks good. Just a few things before merging, please check my comments.

Happy to help with the fixes as well.

"default": "./dist/astro/middleware/redirect.mjs"
},
"./ui": "./src/ui.ts",
"./ui/comments": "./src/ui-comments.ts",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CI is failing because this points to a raw TypeScript file.

```astro
---
import { Comments, CommentForm } from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks like the template copies still have the old import. Try running ./scripts/sync-template-skills.sh should update them all.

@ascorbic

Copy link
Copy Markdown
Collaborator

My concern here is that this is a breaking change. Any site that uses comments will break if they upgrade. I think it doesn't need to be: we can add the subpath export for this and the other components, while leaving the barrel untouched. We can then update templates to import from e.g. emdash/ui/pt. Existing sites stay working, but the new templates and docs are updated with the improved optimisation.

@scottbuscemi

Copy link
Copy Markdown
Collaborator Author

I was okay with this being a pre-1.0 breaking change. Less maintenance burden moving forward, no?

@ascorbic

Copy link
Copy Markdown
Collaborator

We can remove the barrel in 1.0, but I want to avoid breaking changes unless they're needed. This time I'd suggest addign subpath exports, changing the barrel re-exports to use @deprecated jsdoc comments and changing all the templates and docs to use the new syntax, and then dropping the barrel in 1.0

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

Labels

area/core area/templates bot:review Trigger an emdashbot code review on this PR review/awaiting-author Reviewed; waiting on the author to respond size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comments/CommentForm CSS bleeds into all pages via emdash/ui barrel import

3 participants