Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/comments-ui-subpath.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"emdash": minor
---

Adds `emdash/ui/comments` for `Comments` and `CommentForm` so their CSS only loads on pages that import them. Importing from `emdash/ui` still works but is deprecated and will be removed in 1.0 — prefer `import { Comments, CommentForm } from "emdash/ui/comments"`.
3 changes: 1 addition & 2 deletions demos/cloudflare/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions demos/playground/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions demos/postgres/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions demos/preview/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions demos/simple/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 2 additions & 1 deletion e2e/fixture-cloudflare/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import { getEmDashEntry } from "emdash";
import { PortableText, Comments, CommentForm } from "emdash/ui";
import { PortableText } from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";

const { slug } = Astro.params;
if (!slug) return Astro.redirect("/404");
Expand Down
3 changes: 2 additions & 1 deletion e2e/fixture/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import { getEmDashEntry } from "emdash";
import { PortableText, Comments, CommentForm } from "emdash/ui";
import { PortableText } from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";

const { slug } = Astro.params;
if (!slug) return Astro.redirect("/404");
Expand Down
3 changes: 1 addition & 2 deletions fixtures/perf-site/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions infra/blog-demo/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions infra/cache-demo/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions infra/do-demo/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions infra/do-solo-demo/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"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.

"./ui/search": "./src/components/LiveSearch.astro",
"./cli": {
"types": "./dist/cli/index.d.mts",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/CommentForm.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @example
* ```astro
* ---
* import { CommentForm } from "emdash/ui";
* import { CommentForm } from "emdash/ui/comments";
* ---
* <CommentForm collection="posts" contentId={post.id} />
* ```
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/Comments.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @example
* ```astro
* ---
* import { Comments } from "emdash/ui";
* import { Comments } from "emdash/ui/comments";
* ---
* <Comments collection="posts" contentId={post.id} threaded />
* ```
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
// Wrapper component with EmDash defaults
export { default as PortableText } from "./PortableText.astro";

// Comment components
/**
* @deprecated Import from `emdash/ui/comments` instead. Barrel re-exports pull
* comment CSS into every page that imports `emdash/ui` (#2039). Will be removed in 1.0.
*/
export { default as Comments } from "./Comments.astro";
/**
* @deprecated Import from `emdash/ui/comments` instead. Barrel re-exports pull
* comment CSS into every page that imports `emdash/ui` (#2039). Will be removed in 1.0.
*/
export { default as CommentForm } from "./CommentForm.astro";

// Widget components
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/ui-comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* EmDash comment components
*
* Kept out of the main `emdash/ui` barrel so their styles are only loaded on
* pages that actually render comments. Importing from `emdash/ui` pulls the
* whole barrel into Astro's CSS module graph, which put comment CSS on every
* page that used e.g. `PortableText` (#2039).
*
* ```astro
* ---
* import { Comments, CommentForm } from "emdash/ui/comments";
* ---
* <Comments collection="posts" contentId={post.data.id} threaded />
* <CommentForm collection="posts" contentId={post.data.id} />
* ```
*/

export { default as Comments } from "./components/Comments.astro";
export { default as CommentForm } from "./components/CommentForm.astro";
14 changes: 11 additions & 3 deletions packages/core/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export {
// Shares the name with the `type Block` re-export above; the
// type and the component live in different namespaces.
Block,
// Comment components
Comments,
CommentForm,
// Widget components
WidgetArea,
// Components object for manual use
Expand All @@ -78,3 +75,14 @@ export {
EmDashBodyStart,
EmDashBodyEnd,
} from "./components/index.js";

/**
* @deprecated Import from `emdash/ui/comments` instead. Barrel re-exports pull
* comment CSS into every page that imports `emdash/ui` (#2039). Will be removed in 1.0.
*/
export { Comments } from "./components/index.js";
/**
* @deprecated Import from `emdash/ui/comments` instead. Barrel re-exports pull
* comment CSS into every page that imports `emdash/ui` (#2039). Will be removed in 1.0.
*/
export { CommentForm } from "./components/index.js";
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import { getEmDashEntry } from "emdash";
import { PortableText, Comments, CommentForm } from "emdash/ui";
import { PortableText } from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";

const { slug } = Astro.params;
if (!slug) return Astro.redirect("/404");
Expand Down
1 change: 1 addition & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"src/components/**",
"src/preview/**",
"src/ui.ts",
"src/ui-comments.ts",
"src/auth/providers/*-admin.tsx"
]
}
1 change: 1 addition & 0 deletions scripts/typecheck-public-source.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const pkgPath = resolve(repoRoot, "packages/core/package.json");
*/
const RUNTIME_COUPLED = new Set([
"./ui", // src/ui.ts -- re-exports Astro <Image>/<PortableText> components
"./ui/comments", // src/ui-comments.ts -- re-exports Astro <Comments>/<CommentForm>
"./auth/providers/github-admin", // .tsx -- admin React + @cloudflare/kumo
"./auth/providers/google-admin", // .tsx -- admin React + @cloudflare/kumo
]);
Expand Down
3 changes: 1 addition & 2 deletions skills/building-emdash-site/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ import { getByline, getBylineBySlug } from "emdash";
import {
PortableText,
Image,
Comments,
CommentForm,
WidgetArea,
EmDashHead,
EmDashBodyStart,
EmDashBodyEnd,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import LiveSearch from "emdash/ui/search";

// Page context (for plugin contributions)
Expand Down
2 changes: 1 addition & 1 deletion skills/building-emdash-site/references/site-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Built-in comments system:

```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.

---
<Comments collection="posts" contentId={post.data.id} threaded />
<CommentForm collection="posts" contentId={post.data.id} />
Expand Down
3 changes: 1 addition & 2 deletions templates/blank/.agents/skills/building-emdash-site/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ import { getByline, getBylineBySlug } from "emdash";
import {
PortableText,
Image,
Comments,
CommentForm,
WidgetArea,
EmDashHead,
EmDashBodyStart,
EmDashBodyEnd,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import LiveSearch from "emdash/ui/search";

// Page context (for plugin contributions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Built-in comments system:

```astro
---
import { Comments, CommentForm } from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
---
<Comments collection="posts" contentId={post.data.id} threaded />
<CommentForm collection="posts" contentId={post.data.id} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ import { getByline, getBylineBySlug } from "emdash";
import {
PortableText,
Image,
Comments,
CommentForm,
WidgetArea,
EmDashHead,
EmDashBodyStart,
EmDashBodyEnd,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import LiveSearch from "emdash/ui/search";

// Page context (for plugin contributions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Built-in comments system:

```astro
---
import { Comments, CommentForm } from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
---
<Comments collection="posts" contentId={post.data.id} threaded />
<CommentForm collection="posts" contentId={post.data.id} />
Expand Down
3 changes: 1 addition & 2 deletions templates/blog-cloudflare/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
3 changes: 1 addition & 2 deletions templates/blog/.agents/skills/building-emdash-site/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ import { getByline, getBylineBySlug } from "emdash";
import {
PortableText,
Image,
Comments,
CommentForm,
WidgetArea,
EmDashHead,
EmDashBodyStart,
EmDashBodyEnd,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import LiveSearch from "emdash/ui/search";

// Page context (for plugin contributions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Built-in comments system:

```astro
---
import { Comments, CommentForm } from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
---
<Comments collection="posts" contentId={post.data.id} threaded />
<CommentForm collection="posts" contentId={post.data.id} />
Expand Down
3 changes: 1 addition & 2 deletions templates/blog/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import {
Image,
PortableText,
Comments,
CommentForm,
WidgetArea,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import Base from "../../layouts/Base.astro";
import PostCard from "../../components/PostCard.astro";
import { getReadingTime } from "../../utils/reading-time";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ import { getByline, getBylineBySlug } from "emdash";
import {
PortableText,
Image,
Comments,
CommentForm,
WidgetArea,
EmDashHead,
EmDashBodyStart,
EmDashBodyEnd,
} from "emdash/ui";
import { Comments, CommentForm } from "emdash/ui/comments";
import LiveSearch from "emdash/ui/search";

// Page context (for plugin contributions)
Expand Down
Loading
Loading