Skip to content

Commit 6a35569

Browse files
committed
fix(showcase/shell-docs): drop redundant env block in next.config.ts; validate NEXT_PUBLIC_BASE_URL at build time
1 parent 6faf3a7 commit 6a35569

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

showcase/shell-docs/next.config.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import type { NextConfig } from "next";
22

3-
const nextConfig: NextConfig = {
4-
env: {
5-
NEXT_PUBLIC_BASE_URL:
6-
process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3003",
7-
},
8-
};
3+
// NEXT_PUBLIC_BASE_URL is inlined automatically by Next.js at build time
4+
// because of the NEXT_PUBLIC_ prefix. Do NOT re-declare it in an `env` block —
5+
// doing so bakes the build-time value into server code and overrides runtime env.
6+
//
7+
// Fail fast during an actual `next build` if the variable is missing, so we
8+
// never ship broken absolute URLs. Other invocations that also load this
9+
// config (e.g. `next lint`, `next dev`) only warn, because failing them on a
10+
// missing value would be noise — consumers are expected to handle the dev
11+
// fallback themselves (e.g. `process.env.NEXT_PUBLIC_BASE_URL ?? "http://localhost:3003"`).
12+
const isNextBuild = process.argv.includes("build");
13+
14+
if (!process.env.NEXT_PUBLIC_BASE_URL) {
15+
if (isNextBuild) {
16+
throw new Error(
17+
"NEXT_PUBLIC_BASE_URL is required for `next build` of showcase/shell-docs. " +
18+
"Set it in the environment (e.g. https://your-domain.example) before running the build.",
19+
);
20+
}
21+
// eslint-disable-next-line no-console
22+
console.warn(
23+
"[shell-docs] NEXT_PUBLIC_BASE_URL is not set; consumers should fall back to a sensible dev default (e.g. http://localhost:3003).",
24+
);
25+
}
26+
27+
const nextConfig: NextConfig = {};
928

1029
export default nextConfig;

showcase/shell-docs/src/components/property-reference.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,24 @@ export function PropertyReference({
2727
collapsable ? true : false,
2828
);
2929

30+
// Detect nested <PropertyReference> children so we can auto-collapse them.
31+
//
32+
// IMPORTANT: We use *reference equality* (`child.type === PropertyReference`)
33+
// rather than a name check (`child.type.name === "PropertyReference"`).
34+
// In production builds, minifiers (Terser/SWC) rename function components to
35+
// short identifiers like `s` or `a`, so `.name` comparisons silently fail and
36+
// the `collapsable` prop never propagates. Reference equality is minifier-safe
37+
// because both sides point to the same function identity after bundling.
38+
//
39+
// Known limitation: React.Children.map only walks *direct* children. A
40+
// <PropertyReference> wrapped inside a <div> (or any other element) will NOT
41+
// be detected here. Callers should nest PropertyReferences as direct
42+
// siblings, not wrapped in other elements, for auto-collapse to work.
3043
const enhancedChildren = React.Children.map(children, (child) => {
31-
if (
32-
React.isValidElement(child) &&
33-
(child.type as any).name === "PropertyReference"
34-
) {
35-
return React.cloneElement(child, { collapsable: true } as Props);
44+
if (React.isValidElement(child) && child.type === PropertyReference) {
45+
return React.cloneElement(child as React.ReactElement<Props>, {
46+
collapsable: true,
47+
});
3648
}
3749
return child;
3850
});
@@ -65,7 +77,9 @@ export function PropertyReference({
6577
<div className="flex-1 space-x-3">
6678
{collapsable ? (
6779
<button
80+
type="button"
6881
onClick={() => setIsCollapsed(!isCollapsed)}
82+
aria-expanded={!isCollapsed}
6983
className="flex gap-x-2 items-center font-mono font-semibold text-[var(--accent)]"
7084
>
7185
<span className="text-xs">

0 commit comments

Comments
 (0)