implement ssr

This commit is contained in:
2026-09-06 23:29:00 -04:00
parent 4e381fe1bc
commit 06d31382e7
17 changed files with 477 additions and 56 deletions
@@ -0,0 +1,22 @@
import { useHydrated } from "../ssr/hydrated";
// The server render and the hydration pass use a fixed locale and timezone so
// both produce identical markup. Once hydrated we switch to the visitor's own
// locale and timezone, which is what the page showed before it was
// server-rendered.
const stableFormatter = new Intl.DateTimeFormat("en-US", {
timeZone: "UTC",
dateStyle: "short",
timeStyle: "medium",
});
export default function FormattedDate({ value }: { value: string }) {
const hydrated = useHydrated();
const date = new Date(value);
return (
<time dateTime={date.toISOString()}>
{hydrated ? date.toLocaleString() : stableFormatter.format(date)}
</time>
);
}
+2 -1
View File
@@ -1,4 +1,5 @@
import type { Post } from "../utils/types";
import FormattedDate from "./formattedDate";
export default function PostRow({ post }: { post: Post }) {
return (
@@ -8,7 +9,7 @@ export default function PostRow({ post }: { post: Post }) {
<h1>{post.title}</h1>
<p>{post.description}</p>
<p className="text-xs opacity-50">
Posted on {new Date(post.createdAt).toLocaleString()}
Posted on <FormattedDate value={post.createdAt} />
</p>
</div>
</a>