router.push and router.replace is not working on production
Unanswered
Tan posted this in #help-forum
TanOP
Problem
In a Next.js App Router (app/ directory) project, router.push("/") and router.replace("/") get stuck in a pending state in production after a form submission.
The API (POST /organizations) completes successfully (200 OK), but navigation never resolves.
Network panel shows stuck RSC fetch requests (onboarding?_rsc=...).
and also "/" is also client side
"use client";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import OnboardingForm from "@/components/onboardingform";
import { checkOnboarding, getUserData } from "@/utils/queries/queries";
export default function Page() {
const router = useRouter();
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const initialize = async () => {
try {
setIsLoading(true);
setError(null);
const onboardingStatus = await checkOnboarding();
if (onboardingStatus) {
router.push("/");
}
} catch (error: any) {
setError("Failed to load onboarding page: " + error.message);
if (error.message.includes("token")) router.push("/sign-in");
} finally {
setIsLoading(false);
}
};
initialize();
}, [router]);
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error}</div>;
return (
<div className="container mx-auto py-8 px-4">
<Card className="w-full max-w-2xl mx-auto">
<CardHeader>
<CardTitle>Set Up Your Organization</CardTitle>
<CardDescription>
Fill in the details below to create your organization profile
</CardDescription>
</CardHeader>
<CardContent>
<OnboardingForm />
</CardContent>
</Card>
</div>
);
}
In a Next.js App Router (app/ directory) project, router.push("/") and router.replace("/") get stuck in a pending state in production after a form submission.
The API (POST /organizations) completes successfully (200 OK), but navigation never resolves.
Network panel shows stuck RSC fetch requests (onboarding?_rsc=...).
and also "/" is also client side
"use client";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import OnboardingForm from "@/components/onboardingform";
import { checkOnboarding, getUserData } from "@/utils/queries/queries";
export default function Page() {
const router = useRouter();
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const initialize = async () => {
try {
setIsLoading(true);
setError(null);
const onboardingStatus = await checkOnboarding();
if (onboardingStatus) {
router.push("/");
}
} catch (error: any) {
setError("Failed to load onboarding page: " + error.message);
if (error.message.includes("token")) router.push("/sign-in");
} finally {
setIsLoading(false);
}
};
initialize();
}, [router]);
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error}</div>;
return (
<div className="container mx-auto py-8 px-4">
<Card className="w-full max-w-2xl mx-auto">
<CardHeader>
<CardTitle>Set Up Your Organization</CardTitle>
<CardDescription>
Fill in the details below to create your organization profile
</CardDescription>
</CardHeader>
<CardContent>
<OnboardingForm />
</CardContent>
</Card>
</div>
);
}
7 Replies
TanOP
next.js version : "next": "^14.2.
"react": "^18.2.0",
"react-dom": "^18.2.0",
I also tried with latest version but issue is same
"react": "^18.2.0",
"react-dom": "^18.2.0",
I also tried with latest version but issue is same
Is the function “checkOnboarding” a server action?
TanOP
No it client making the post request by axios to /organisation
&752637460550385834 please help me with this issue
@Tan <@&752637460550385834> please help me with this issue
please only ping moderators for moderation issues
@Tan next.js version : "next": "^14.2.
"react": "^18.2.0",
"react-dom": "^18.2.0",
I also tried with latest version but issue is same
Ojos Azules
can you recreate the issue using the sandbox, for API you can create a dummy function with a promise
TanOP
@Ojos Azules Can we connect so we can jump directly to the issue?