Add a feedback widget to a Next.js app
A client component loads the embed script with next/script and mounts into a ref.
Free for one project and 100 votes. Paid plans start with a 14 day trial, no card.
App Router
Mark the file with 'use client', load the script with next/script and call the widget from an effect.
One client component draws the widget.
Server components can render it like any other client component.
The widget call touches window and the element it draws into, so it cannot run on the server. That is why the file starts with 'use client' and why every call sits inside useEffect, which runs only in the browser after the page has mounted.
next/script loads the file itself. The component does not wait for an onLoad callback. It pushes a function onto window.vfq, a queue the script drains, and the queue runs your function whether the script arrived a moment ago or arrives a moment later. That removes the race between your effect and the download.
The effect returns a cleanup that destroys the widget, so a route change or a hot reload leaves no stale copy behind. The two props are the project slug and the embed key, both shown under Share and Embed in the dashboard.
'use client';
import { useEffect, useRef } from 'react';
import Script from 'next/script';
export default function VoteFirstRoadmap({ project, embedKey }: { project: string; embedKey: string }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
let handle: { destroy: () => void } | undefined;
let cancelled = false;
(window as any).vfq = (window as any).vfq || [];
(window as any).vfq.push((VoteFirst: any) => {
if (cancelled) return;
VoteFirst.init({ project, key: embedKey });
handle = VoteFirst.roadmap(ref.current);
});
return () => {
cancelled = true;
handle?.destroy();
};
}, [project, embedKey]);
return (
<>
<Script src="https://app.votefirst.app/embed/votefirst.js" strategy="afterInteractive" />
<div ref={ref} />
</>
);
}<VoteFirstRoadmap project="your-project-slug" embedKey="your-embed-key" />Other widgets
VoteFirst.roadmap is one of several calls. The board, the changelog, a vote button and the popups work the same way.
Swap one call to draw something else.
Everything else in the component stays as it is.
The component above is a shell: load the script, init once, mount into the ref, destroy on the way out. Only the line that names the widget changes. Replace VoteFirst.roadmap with the call for the board, the changelog, the Most Wanted list, a vote button, a badge or either popup, and the rest holds.
If a page needs two widgets, keep one component per widget instead of one component that draws both. Each then owns its own ref, its own handle and its own cleanup, and removing one from a page cannot disturb the other.
Pages Router
In the Pages Router, render next/script from a page or from _app.tsx, never from _document.tsx.
The same component works. Only the script moves.
The effect, the ref and the cleanup do not change.
The one difference is where next/script with strategy afterInteractive is allowed to sit. In the App Router it can live inside the component, as above. In the Pages Router it has to be rendered from a page or from _app.tsx, because _document.tsx runs before the page is interactive and the strategy has nothing to wait for there.
So in a Pages Router app, lift the Script element out of the component into _app.tsx, and keep the div, the ref and the effect where they are. The queue on window.vfq still makes the order of the two irrelevant.
Strict Mode
Next.js runs React Strict Mode by default, which runs an effect, tears it down and runs it again.
Mounting twice in development is expected.
Only the second run's widget stays on screen.
In development you may see the effect fire twice. The first run usually queues its call before the script has arrived, so when its cleanup runs there is nothing to destroy yet. Without a guard, that queued call would still fire later and draw a second widget on top of the first.
The cancelled flag is the guard. The cleanup sets it, the queued call checks it and returns without drawing, and only the second run produces a widget. A production build does not double the effect, so the flag costs nothing there and keeps development honest.
If you remove the flag to simplify the component, you will see two boards in development and one in production, which is the symptom to remember.
origin_not_allowed
Add every origin that loads the page to the embed key's allowlist under Share and Embed.
A 403 means the origin is not on the list.
Localhost counts as an origin, port included.
origin_not_allowed arrives as a 403. The embed key only answers pages whose origin it knows, and an origin is the scheme, the host and the port together. http://localhost:3000 is one origin, your deployed domain is another, and a preview deployment on a generated address is a third.
Add the development origin and the production one to the allowlist in the dashboard. For preview deployments, add the preview address too, or test them against a project whose list includes it.
window is not defined
The build fails when server rendering reaches a read of window or document.
Keep window inside the effect.
Add 'use client' and move the read into useEffect.
window is not defined during next build means a component read window outside useEffect, or lacks 'use client' and so ran on the server, where no window exists. Server rendering visits every page the build touches, so one stray read fails the whole build.
The fix is the shape of the component above. Every read of window or document sits inside the effect, and the effect only runs in the browser. If you wrote a helper that touches window at import time, move that touch into the effect too.
What you end up with
A widget that cleans up
A route change destroys the widget, and the next page draws a fresh one.
No load race
The queue runs your call whether the script has arrived or not.
A build that passes
Every read of window sits in the effect, so server rendering never reaches it.
Add the widget in four steps
One file, one prop pair, one allowlist entry.
Create the component
Save the client component as VoteFirstRoadmap.tsx in your components folder.
Pass the project and key
Copy the slug and the embed key from Share and Embed in the dashboard.
Allow your origins
Add http://localhost:3000 and your deployed origin to the key's allowlist.
Render it in a page
Place the component where the roadmap should appear and open the page.
What to know before you ship it
- The widget draws in the browser, so its content is not in the server rendered HTML and search engines read the page without it.
- The embed key is meant for pages, but keep it in an environment variable so one value serves every environment.
- A preview deployment on a generated address needs its own allowlist entry.
- The component draws one widget. A page that needs two should use two components.
Next.js widget questions
Does the widget work with the App Router?
Yes. Put it in a client component marked with 'use client' and render that component from any page or server component.
Is an onLoad callback needed on the script?
No. The component pushes a function onto window.vfq, and the queue runs it whether the script has arrived or not.
Where does next/script go in the Pages Router?
In a page or in _app.tsx. It must not sit in _document.tsx, which runs before the page is interactive.
Why does the widget mount twice in development?
React Strict Mode runs the effect twice. The cancelled flag makes the first queued call return, so one widget appears.
What does origin_not_allowed mean?
The page's origin is missing from the embed key's allowlist. Add localhost and your deployed origin under Share and Embed.
How is window is not defined fixed?
Add 'use client' and keep every read of window or document inside useEffect, so server rendering never reaches it.
Can the same component draw the board or the changelog?
Yes. Replace the VoteFirst.roadmap call with the call for that widget and leave the rest as it is.
What does it cost?
Free covers one project and 100 votes. After that, Lite is $9/mo and Pro is $39/mo, each after a 14 day trial with no card.
Is there a Nextjs feedback widget?
Yes. In Next.js the widget lives in a client component that loads the embed script with next/script and mounts into a ref.
More ways to add a board
More on the embed script and where it fits.
Ship the roadmap with your next deploy
Start on Free with one project and 100 votes. When the board grows, Lite is $9/mo and Pro is $39/mo, each after a 14 day trial and no card.