Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 3 additions & 21 deletions apps/web/src/app/(home)/new/_components/stack-builder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function StackBuilder({ specialSponsors = [] }: StackBuilderProps) {
</span>
</div>
<SelectedStackBadges
stack={stack}
stack={effectiveStack}
onRemove={removeSelectedTech}
Comment thread
AmanVarshney01 marked this conversation as resolved.
Resolved
onJump={(category) => {
if (viewMode !== "command") {
Expand All @@ -241,24 +241,6 @@ export function StackBuilder({ specialSponsors = [] }: StackBuilderProps) {
/>
</section>

{compatibilityAnalysis.changes.length > 0 && (
<section className="space-y-2 border-border/20 border-t px-3 py-3">
<p className="font-mono text-[11px] text-primary uppercase tracking-wide">
Compatibility Log
</p>
<ul className="space-y-1 rounded-lg bg-primary/7 px-2.5 py-2">
{compatibilityAnalysis.changes.slice(0, 4).map((change, index) => (
<li
key={`${change.category}-${change.message}-${index}`}
className="text-muted-foreground text-xs"
>
• {change.message}
</li>
))}
</ul>
</section>
)}

{desktopBuildNote && (
<section className="space-y-2 border-border/20 border-t px-3 py-3">
<div className="flex items-center gap-1.5 font-mono text-[11px] text-amber-600 uppercase tracking-wide dark:text-amber-400">
Expand Down Expand Up @@ -332,7 +314,7 @@ export function StackBuilder({ specialSponsors = [] }: StackBuilderProps) {
<main className="p-2 sm:p-4">
<TechCategories
mode="desktop"
stack={stack}
stack={effectiveStack}
compatibilityNotes={compatibilityAnalysis.notes}
onSelect={handleTechSelect}
showAllCategories
Expand Down Expand Up @@ -468,7 +450,7 @@ export function StackBuilder({ specialSponsors = [] }: StackBuilderProps) {

<TechCategories
mode="mobile"
stack={stack}
stack={effectiveStack}
compatibilityNotes={compatibilityAnalysis.notes}
onSelect={handleTechSelect}
showAllCategories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,40 @@ export function getCompatibilityAdjustmentState(
};
}

export function getLatestCompatibilityAdjustment(stack: StackState): Partial<StackState> {
return analyzeStackCompatibility(stack).adjustedStack ?? {};
}

export function getSelectedTechRemovalUpdate(
stack: StackState,
category: TechCategory,
techId: string,
): Partial<StackState> {
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<StackState>;
}

if (value === techId && hasNoneOption) {
return { [categoryKey]: "none" } as Partial<StackState>;
}

return {};
}

export function useStackBuilder() {
const [stack, setStack, viewMode, setViewMode, selectedFile, setSelectedFile] = useStackState();

const [command, setCommand] = useState("");
const [copied, setCopied] = useState(false);
const [lastSavedStack, setLastSavedStack] = useState<StackState | null>(null);
const [, setLastChanges] = useState<Array<{ category: string; message: string }>>([]);
const [mobileTab, setMobileTab] = useState<MobileTab>("build");

const contentRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -105,33 +132,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((currentStack) => getLatestCompatibilityAdjustment(currentStack));
}, [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<Array<CategoryProgressItem>>(() => {
Expand Down Expand Up @@ -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<StackState>);
});
return;
}

if (value === techId && hasNoneOption) {
startTransition(() => {
setStack({ [categoryKey]: "none" } as Partial<StackState>);
});
}
startTransition(() => {
setStack((currentStack) => getSelectedTechRemovalUpdate(currentStack, category, techId));
});
}

async function copyToClipboard() {
Expand Down
91 changes: 57 additions & 34 deletions apps/web/src/lib/stack-url-state.client.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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<StackState> | ((prev: StackState) => Partial<StackState>),
) => {
const newStack = typeof updates === "function" ? updates(stack) : updates;
const finalStack = sanitizeStackState({ ...stack, ...newStack });
await setQueryState({ ...finalStack, viewMode, selectedFile });
};
const updateStack = useCallback(
async (updates: Partial<StackState> | ((prev: StackState) => Partial<StackState>)) => {
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;
}
39 changes: 39 additions & 0 deletions apps/web/test/stack-builder-compatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { describe, expect, test } from "bun:test";
import {
getCompatibilityAdjustmentKey,
getCompatibilityAdjustmentState,
getLatestCompatibilityAdjustment,
getSelectedTechRemovalUpdate,
} from "../src/app/(home)/new/_components/stack-builder/use-stack-builder";
import {
analyzeStackCompatibility,
Expand Down Expand Up @@ -235,6 +237,43 @@ describe("stack builder D1 compatibility", () => {
expect(command).toContain("--payments polar");
});

test("keeps Expo selected when Nuxt switches the API to oRPC", () => {
const staleStack = createStack({
webFrontend: ["nuxt"],
nativeFrontend: ["none"],
api: "trpc",
});
const latestStack = createStack({
webFrontend: ["nuxt"],
nativeFrontend: ["native-bare"],
api: "trpc",
});

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"],
api: "orpc",
});
expect(getDisabledReason(adjustedStack, "nativeFrontend", "native-bare")).toBeNull();
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"],
Expand Down
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.