High-Performance Next.js App Router & Pages Router Integration
Deploy Rajlav AI with zero impact on Next.js Core Web Vitals. Utilize `next/script` with `strategy="afterInteractive"` for flawless Server-Side Rendering (SSR) and static generation.
import Script from 'next/script';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://staging.rajlav.co.in/widget/smart-connect.js"
data-business-id={process.env.NEXT_PUBLIC_RAJLAV_BUSINESS_ID}
data-position="bottom-right"
strategy="afterInteractive"
/>
</body>
</html>
);
}Engineered for Performance & Scalability
Core Web Vitals Safe
Loads after hydration completes, ensuring 100/100 Lighthouse performance scores.
App Router & Pages Router
Fully compatible with Next.js 14, 15, root layouts (`layout.tsx`), and classic `_app.tsx`.
Zero Hydration Mismatch
Engineered to avoid React hydration errors and DOM mutation warnings during mount.
Route Change Persistence
Maintains open chat sessions seamlessly across soft page navigations.
How to Connect Next.js in 4 Steps
Import Script in layout.tsx
Import `Script` from `next/script` inside your root `app/layout.tsx` file.
Configure Attributes
Set `src`, `data-business-id`, and `strategy="afterInteractive"`.
Set Environment Variables
Optionally store your Business ID in `process.env.NEXT_PUBLIC_RAJLAV_BUSINESS_ID`.
Deploy to Vercel or Node
Runs cleanly on Vercel, AWS Amplify, Docker, and standard Node servers.
Compatible Rajlav AI Modules
Frequently Asked Questions
Will this cause Next.js hydration mismatch errors?
No! Because `next/script` with `afterInteractive` executes strictly on the client post-hydration, there is zero risk of hydration mismatches.
Does it work with static site generation (SSG) and ISR?
Yes! Completely compatible with static generation (`output: export`), ISR, and dynamic server rendering.
Can I disable the widget on specific Next.js subpaths like /admin?
Yes! You can conditionally render the `<Script />` component based on the active pathname using `usePathname()`.
