[ Install guide ]
Feedback widget for Next.js
Load the widget with next/script in your root layout. Feedback sent from the live site is implemented by an AI agent and arrives as a pull request in your repository.
Updated
Before you start
- Sign in with GitHub and install the feedback2code GitHub App. Choose the repository that holds the code of the site.
- Open the repository in the dashboard, go to Configure and add the domains the widget may run on.
- Copy the snippet from Embed Widget. It contains your widget ID.
Add the widget
import Script from "next/script";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://www.feedback2code.dev/widget/YOUR_WIDGET_ID"
strategy="afterInteractive"
/>
</body>
</html>
);
}Replace YOUR_WIDGET_ID with the ID from your dashboard. With the Pages Router, put the same <Script> element into pages/_app.tsx. afterInteractive loads the widget once the page is usable, so it does not compete with your own code.
What the agent can change
The agent works on the repository of the Next.js app: components, pages, styles, content files. It runs in a Linux sandbox, where it can install packages from the npm registry and run your scripts.
Every change arrives as a pull request. Nothing is merged or deployed until you do it, so your usual review and deployment stay as they are.
Good to know
- Add localhost to the authorized domains to try the widget during development. A test submission counts like any other and starts the agent.
- With a Content-Security-Policy, allow https://www.feedback2code.dev in script-src and frame-src.
- The widget records the address of the page it was loaded on. In a single-page navigation the address is not updated, so ask reporters to name the page if it matters.
- Preview deployments have their own hostnames. Authorize your project's preview domain, not vercel.app as a whole.
Test it
- Deploy the change and open the site on an authorized domain.
- Click the button at the bottom right and send one small, concrete request.
- Open your dashboard. The submission starts as coding and turns to awaiting review once the pull request is open.
What a submission contains and how the plans differ is described on the page about the website feedback widget.
Other setups
- Feedback widget for React apps
- Feedback widget for Vue and Nuxt
- Feedback widget for Astro
- Feedback widget for static HTML sites
- Feedback widget for WordPress themes
- Feedback widget for Shopify themes
Questions and answers
Does the widget slow down my Next.js app?
It is one small external script that loads after the page is interactive and renders the widget in an iframe. It does not add packages to your bundle.
Is there an npm package?
No. The widget is a script tag. With next/script you place it in the layout once and it appears on every page.
Does it work with the App Router and the Pages Router?
Yes. Use app/layout.tsx with the App Router and pages/_app.tsx with the Pages Router.