From eae226166743be14d679e0741b36d56f4f99afb5 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sat, 1 Aug 2026 02:14:44 +0530 Subject: [PATCH 1/4] fix(web): stabilize stack builder URL state --- apps/web/package.json | 2 +- .../new/_components/stack-builder/index.tsx | 24 +---- .../stack-builder/use-stack-builder.ts | 34 +++---- apps/web/src/lib/stack-url-state.client.ts | 91 ++++++++++++------- bun.lock | 4 +- 5 files changed, 78 insertions(+), 77 deletions(-) diff --git a/apps/web/package.json b/apps/web/package.json index 406b6b3a7..b356b84a4 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -44,7 +44,7 @@ "motion": "^12.43.0", "next": "^16.2.12", "next-themes": "^0.4.6", - "nuqs": "^2.9.2", + "nuqs": "^2.9.4", "papaparse": "^5.5.4", "qrcode": "^1.5.4", "radix-ui": "^1.6.7", diff --git a/apps/web/src/app/(home)/new/_components/stack-builder/index.tsx b/apps/web/src/app/(home)/new/_components/stack-builder/index.tsx index 1178eaccc..870248ab2 100644 --- a/apps/web/src/app/(home)/new/_components/stack-builder/index.tsx +++ b/apps/web/src/app/(home)/new/_components/stack-builder/index.tsx @@ -228,7 +228,7 @@ export function StackBuilder({ specialSponsors = [] }: StackBuilderProps) { { if (viewMode !== "command") { @@ -241,24 +241,6 @@ export function StackBuilder({ specialSponsors = [] }: StackBuilderProps) { /> - {compatibilityAnalysis.changes.length > 0 && ( -
-

- Compatibility Log -

-
    - {compatibilityAnalysis.changes.slice(0, 4).map((change, index) => ( -
  • - • {change.message} -
  • - ))} -
-
- )} - {desktopBuildNote && (
@@ -332,7 +314,7 @@ export function StackBuilder({ specialSponsors = [] }: StackBuilderProps) {
(null); - const [, setLastChanges] = useState>([]); const [mobileTab, setMobileTab] = useState("build"); const contentRef = useRef(null); @@ -105,33 +103,31 @@ export function useStackBuilder() { adjustedStack, ); - if (!shouldApply) { + if (!adjustedStack || !shouldApply) { lastAppliedAdjustmentKey.current = adjustmentKey; return; } - startTransition(() => { - if (compatibilityAnalysis.changes.length === 1) { - toast.info(compatibilityAnalysis.changes[0].message, { duration: 4000 }); - } + lastAppliedAdjustmentKey.current = adjustmentKey; - if (compatibilityAnalysis.changes.length > 1) { - const message = `${compatibilityAnalysis.changes.length} compatibility adjustments made:\n${compatibilityAnalysis.changes - .map((change) => `• ${change.message}`) - .join("\n")}`; + if (compatibilityAnalysis.changes.length === 1) { + toast.info(compatibilityAnalysis.changes[0].message, { duration: 4000 }); + } - toast.info(message, { duration: 5000 }); - } + if (compatibilityAnalysis.changes.length > 1) { + const message = `${compatibilityAnalysis.changes.length} compatibility adjustments made:\n${compatibilityAnalysis.changes + .map((change) => `• ${change.message}`) + .join("\n")}`; - setLastChanges(compatibilityAnalysis.changes); - setStack(adjustedStack!); - lastAppliedAdjustmentKey.current = adjustmentKey; - }); + toast.info(message, { duration: 5000 }); + } + + void setStack(adjustedStack); }, [stack, compatibilityAnalysis.adjustedStack, compatibilityAnalysis.changes, setStack]); - useEffect(() => { + const command = useMemo(() => { const stackToUse = compatibilityAnalysis.adjustedStack || stack; - setCommand(generateStackCommand(withFormattedProjectName(stackToUse))); + return generateStackCommand(withFormattedProjectName(stackToUse)); }, [stack, compatibilityAnalysis.adjustedStack]); const categoryProgress = useMemo>(() => { diff --git a/apps/web/src/lib/stack-url-state.client.ts b/apps/web/src/lib/stack-url-state.client.ts index 4a7881f57..285f597eb 100644 --- a/apps/web/src/lib/stack-url-state.client.ts +++ b/apps/web/src/lib/stack-url-state.client.ts @@ -1,5 +1,6 @@ "use client"; import { parseAsArrayOf, parseAsString, parseAsStringEnum, useQueryStates } from "nuqs"; +import { useCallback, useMemo } from "react"; import { DEFAULT_STACK, type StackState, TECH_OPTIONS } from "@/lib/constant"; @@ -64,46 +65,68 @@ export const stackQueryStatesOptions = { export function useStackState() { const [queryState, setQueryState] = useQueryStates(stackParsers, stackQueryStatesOptions); - const stack = sanitizeStackState({ - projectName: queryState.projectName, - webFrontend: queryState.webFrontend, - nativeFrontend: queryState.nativeFrontend, - runtime: queryState.runtime, - backend: queryState.backend, - api: queryState.api, - database: queryState.database, - orm: queryState.orm, - dbSetup: queryState.dbSetup, - auth: queryState.auth, - payments: queryState.payments, - packageManager: queryState.packageManager, - addons: queryState.addons, - examples: queryState.examples, - git: queryState.git, - install: queryState.install, - webDeploy: queryState.webDeploy, - serverDeploy: queryState.serverDeploy, - yolo: queryState.yolo, - }); + const stack = useMemo( + () => + sanitizeStackState({ + projectName: queryState.projectName, + webFrontend: queryState.webFrontend, + nativeFrontend: queryState.nativeFrontend, + runtime: queryState.runtime, + backend: queryState.backend, + api: queryState.api, + database: queryState.database, + orm: queryState.orm, + dbSetup: queryState.dbSetup, + auth: queryState.auth, + payments: queryState.payments, + packageManager: queryState.packageManager, + addons: queryState.addons, + examples: queryState.examples, + git: queryState.git, + install: queryState.install, + webDeploy: queryState.webDeploy, + serverDeploy: queryState.serverDeploy, + yolo: queryState.yolo, + }), + [queryState], + ); const viewMode = queryState.viewMode; const selectedFile = queryState.selectedFile; - const updateStack = async ( - updates: Partial | ((prev: StackState) => Partial), - ) => { - const newStack = typeof updates === "function" ? updates(stack) : updates; - const finalStack = sanitizeStackState({ ...stack, ...newStack }); - await setQueryState({ ...finalStack, viewMode, selectedFile }); - }; + const updateStack = useCallback( + async (updates: Partial | ((prev: StackState) => Partial)) => { + await setQueryState((currentQueryState) => { + const currentStack = sanitizeStackState(currentQueryState); + const newStack = typeof updates === "function" ? updates(currentStack) : updates; + const finalStack = sanitizeStackState({ ...currentStack, ...newStack }); - const setViewMode = async (mode: "command" | "preview") => { - await setQueryState({ viewMode: mode, selectedFile }); - }; + return { + ...finalStack, + viewMode: currentQueryState.viewMode, + selectedFile: currentQueryState.selectedFile, + }; + }); + }, + [setQueryState], + ); - const setSelectedFile = async (filePath: string | null) => { - await setQueryState({ selectedFile: filePath || "" }); - }; + const setViewMode = useCallback( + async (mode: "command" | "preview") => { + await setQueryState((currentQueryState) => ({ + viewMode: mode, + selectedFile: currentQueryState.selectedFile, + })); + }, + [setQueryState], + ); + + const setSelectedFile = useCallback( + async (filePath: string | null) => { + await setQueryState({ selectedFile: filePath || "" }); + }, + [setQueryState], + ); return [stack, updateStack, viewMode, setViewMode, selectedFile, setSelectedFile] as const; } diff --git a/bun.lock b/bun.lock index 2be0ff880..66d3b19a1 100644 --- a/bun.lock +++ b/bun.lock @@ -93,7 +93,7 @@ "motion": "^12.43.0", "next": "^16.2.12", "next-themes": "^0.4.6", - "nuqs": "^2.9.2", + "nuqs": "^2.9.4", "papaparse": "^5.5.4", "qrcode": "^1.5.4", "radix-ui": "^1.6.7", @@ -2047,7 +2047,7 @@ "number-flow": ["number-flow@0.6.2", "", { "dependencies": { "esm-env": "^1.1.4" } }, "sha512-MCnImG4Q5vPwhSXnov56nOuyyKn6LC+Qd7II1UiKc+ACRtug5iAtn0+CwXNxM38AC5lSowEY+oYEtZX2qMnUyw=="], - "nuqs": ["nuqs@2.9.2", "", { "dependencies": { "@standard-schema/spec": "1.1.0" }, "peerDependencies": { "@remix-run/react": ">=2", "@tanstack/react-router": "^1", "next": ">=14.2.0", "react": ">=18.2.0 || ^19.0.0-0", "react-router": "^5 || ^6 || ^7 || ^8", "react-router-dom": "^5 || ^6 || ^7" }, "optionalPeers": ["@remix-run/react", "@tanstack/react-router", "next", "react-router", "react-router-dom"] }, "sha512-SUrBU5PfLckv2SAquHkYs76s603vbjl2OLEc+jlL3sITwvJDbE/fg3vN7l9Rdp4WIUs6E0QD+m3DfH9QUQfLkg=="], + "nuqs": ["nuqs@2.9.4", "", { "dependencies": { "@standard-schema/spec": "1.1.0" }, "peerDependencies": { "@remix-run/react": ">=2", "@tanstack/react-router": "^1", "next": ">=14.2.0", "react": ">=18.2.0 || ^19.0.0-0", "react-router": "^5 || ^6 || ^7 || ^8", "react-router-dom": "^5 || ^6 || ^7" }, "optionalPeers": ["@remix-run/react", "@tanstack/react-router", "next", "react-router", "react-router-dom"] }, "sha512-lsz3NyCOKmuNAyW052i9RWqcTntoYb2Qm6FxSWnkTDwOJnGS6fzpXDAp0VcwTevw3xgnWebYpDr9rm6+o4DHbw=="], "nypm": ["nypm@0.6.5", "", { "dependencies": { "citty": "^0.2.0", "pathe": "^2.0.3", "tinyexec": "^1.0.2" }, "bin": { "nypm": "dist/cli.mjs" } }, "sha512-K6AJy1GMVyfyMXRVB88700BJqNUkByijGJM8kEHpLdcAt+vSQAVfkWWHYzuRXHSY6xA2sNc5RjTj0p9rE2izVQ=="], From a2c28d55b26532ab46bf63199fd48222386dd368 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sat, 1 Aug 2026 02:16:05 +0530 Subject: [PATCH 2/4] test(web): cover Nuxt and Expo selection --- .../test/stack-builder-compatibility.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/web/test/stack-builder-compatibility.test.ts b/apps/web/test/stack-builder-compatibility.test.ts index c349ad93b..7153a7bc2 100644 --- a/apps/web/test/stack-builder-compatibility.test.ts +++ b/apps/web/test/stack-builder-compatibility.test.ts @@ -235,6 +235,25 @@ describe("stack builder D1 compatibility", () => { expect(command).toContain("--payments polar"); }); + test("keeps Expo selected when Nuxt switches the API to oRPC", () => { + const stack = createStack({ + webFrontend: ["nuxt"], + nativeFrontend: ["native-bare"], + api: "trpc", + }); + + const result = analyzeStackCompatibility(stack); + const adjustedStack = result.adjustedStack ?? stack; + + expect(adjustedStack).toMatchObject({ + webFrontend: ["nuxt"], + nativeFrontend: ["native-bare"], + api: "orpc", + }); + expect(getDisabledReason(adjustedStack, "nativeFrontend", "native-bare")).toBeNull(); + expect(generateStackCommand(adjustedStack)).toContain("--frontend nuxt native-bare"); + }); + test("blocks the AI example for Astro frontends", () => { const stack = createStack({ webFrontend: ["astro"], From bafe07bb72c3d2f390d8593ed388477fc7c770ae Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sat, 1 Aug 2026 02:23:15 +0530 Subject: [PATCH 3/4] fix(web): preserve concurrent stack selections --- .../_components/stack-builder/use-stack-builder.ts | 6 +++++- apps/web/test/stack-builder-compatibility.test.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts b/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts index 7edef6f22..531734103 100644 --- a/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts +++ b/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts @@ -55,6 +55,10 @@ export function getCompatibilityAdjustmentState( }; } +export function getLatestCompatibilityAdjustment(stack: StackState): Partial { + return analyzeStackCompatibility(stack).adjustedStack ?? {}; +} + export function useStackBuilder() { const [stack, setStack, viewMode, setViewMode, selectedFile, setSelectedFile] = useStackState(); @@ -122,7 +126,7 @@ export function useStackBuilder() { toast.info(message, { duration: 5000 }); } - void setStack(adjustedStack); + void setStack((currentStack) => getLatestCompatibilityAdjustment(currentStack)); }, [stack, compatibilityAnalysis.adjustedStack, compatibilityAnalysis.changes, setStack]); const command = useMemo(() => { diff --git a/apps/web/test/stack-builder-compatibility.test.ts b/apps/web/test/stack-builder-compatibility.test.ts index 7153a7bc2..8dc94b6d7 100644 --- a/apps/web/test/stack-builder-compatibility.test.ts +++ b/apps/web/test/stack-builder-compatibility.test.ts @@ -3,6 +3,7 @@ import { describe, expect, test } from "bun:test"; import { getCompatibilityAdjustmentKey, getCompatibilityAdjustmentState, + getLatestCompatibilityAdjustment, } from "../src/app/(home)/new/_components/stack-builder/use-stack-builder"; import { analyzeStackCompatibility, @@ -236,15 +237,22 @@ describe("stack builder D1 compatibility", () => { }); test("keeps Expo selected when Nuxt switches the API to oRPC", () => { - const stack = createStack({ + const staleStack = createStack({ + webFrontend: ["nuxt"], + nativeFrontend: ["none"], + api: "trpc", + }); + const latestStack = createStack({ webFrontend: ["nuxt"], nativeFrontend: ["native-bare"], api: "trpc", }); - const result = analyzeStackCompatibility(stack); - const adjustedStack = result.adjustedStack ?? stack; + const staleAdjustment = analyzeStackCompatibility(staleStack).adjustedStack; + const latestAdjustment = getLatestCompatibilityAdjustment(latestStack); + const adjustedStack = { ...latestStack, ...latestAdjustment }; + expect(staleAdjustment?.nativeFrontend).toEqual(["none"]); expect(adjustedStack).toMatchObject({ webFrontend: ["nuxt"], nativeFrontend: ["native-bare"], From ae0a08eb1eac2a2bf6c547c8d612773f2849674a Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sat, 1 Aug 2026 02:25:21 +0530 Subject: [PATCH 4/4] fix(web): align badge actions with effective stack --- .../stack-builder/use-stack-builder.ts | 48 +++++++++++-------- .../test/stack-builder-compatibility.test.ts | 12 +++++ 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts b/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts index 531734103..bdf5f7b6a 100644 --- a/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts +++ b/apps/web/src/app/(home)/new/_components/stack-builder/use-stack-builder.ts @@ -59,6 +59,31 @@ export function getLatestCompatibilityAdjustment(stack: StackState): Partial { + const effectiveStack = analyzeStackCompatibility(stack).adjustedStack ?? stack; + const categoryKey = category as keyof StackState; + const value = effectiveStack[categoryKey]; + const options = TECH_OPTIONS[category] || []; + const hasNoneOption = options.some((option) => option.id === "none"); + const forceNoneFallback = category === "addons" || category === "examples"; + + if (Array.isArray(value)) { + const next = value.filter((id) => id !== techId); + const fallback = next.length === 0 && (hasNoneOption || forceNoneFallback) ? ["none"] : next; + return { [categoryKey]: fallback } as Partial; + } + + if (value === techId && hasNoneOption) { + return { [categoryKey]: "none" } as Partial; + } + + return {}; +} + export function useStackBuilder() { const [stack, setStack, viewMode, setViewMode, selectedFile, setSelectedFile] = useStackState(); @@ -311,26 +336,9 @@ export function useStackBuilder() { } function removeSelectedTech(category: TechCategory, techId: string) { - const categoryKey = category as keyof StackState; - const value = stack[categoryKey]; - const options = TECH_OPTIONS[category] || []; - const hasNoneOption = options.some((option) => option.id === "none"); - const forceNoneFallback = category === "addons" || category === "examples"; - - if (Array.isArray(value)) { - const next = value.filter((id) => id !== techId); - const fallback = next.length === 0 && (hasNoneOption || forceNoneFallback) ? ["none"] : next; - startTransition(() => { - setStack({ [categoryKey]: fallback } as Partial); - }); - return; - } - - if (value === techId && hasNoneOption) { - startTransition(() => { - setStack({ [categoryKey]: "none" } as Partial); - }); - } + startTransition(() => { + setStack((currentStack) => getSelectedTechRemovalUpdate(currentStack, category, techId)); + }); } async function copyToClipboard() { diff --git a/apps/web/test/stack-builder-compatibility.test.ts b/apps/web/test/stack-builder-compatibility.test.ts index 8dc94b6d7..1caec46fe 100644 --- a/apps/web/test/stack-builder-compatibility.test.ts +++ b/apps/web/test/stack-builder-compatibility.test.ts @@ -4,6 +4,7 @@ import { getCompatibilityAdjustmentKey, getCompatibilityAdjustmentState, getLatestCompatibilityAdjustment, + getSelectedTechRemovalUpdate, } from "../src/app/(home)/new/_components/stack-builder/use-stack-builder"; import { analyzeStackCompatibility, @@ -262,6 +263,17 @@ describe("stack builder D1 compatibility", () => { expect(generateStackCommand(adjustedStack)).toContain("--frontend nuxt native-bare"); }); + test("removes a compatibility-adjusted badge against the effective stack", () => { + const rawStack = createStack({ + webFrontend: ["nuxt"], + nativeFrontend: ["native-bare"], + api: "trpc", + }); + + expect(analyzeStackCompatibility(rawStack).adjustedStack?.api).toBe("orpc"); + expect(getSelectedTechRemovalUpdate(rawStack, "api", "orpc")).toEqual({ api: "none" }); + }); + test("blocks the AI example for Astro frontends", () => { const stack = createStack({ webFrontend: ["astro"],