Feedback button for a Docusaurus site
Load the script from your Docusaurus config and add a React button that cleans up on page change.
Free for one project and 100 votes. Paid plans start with a 14 day trial, no card.
The catch
The embed script finds the element named by a selector at the moment you call it. A button that React draws later is not found.
A trigger is bound once, so a page that changes needs a component.
A DOM element can be passed in place of the selector.
On a plain page the button sits in the HTML before the script runs, so a selector such as #suggest-btn works. In Docusaurus the navigation between docs pages is done by React in the browser, which means the button comes and goes while the script stays loaded. A selector resolved once at load would miss every button drawn after it.
The call returns a handle with open, close and destroy. Passing the real button element and calling destroy when the component leaves the page avoids both the miss and a second problem. A repeated call leaves an old listener behind, and one click then opens two dialogs.
Load the script
Docusaurus accepts an object in the scripts array and writes each one into the head. Put the VoteFirst attributes on that object.
Add the script to the scripts list in the site config.
Leave out async and defer so the script is ready first.
The Docusaurus reference says each item in scripts is a string or a plain object of attributes, inserted in the head. It says these tags block rendering unless you add async or defer. Blocking is what you want here. It means window.VoteFirst exists before any component runs its effect, so the component needs no waiting code.
The slug and the key come from the Share and Embed screen of your project. The key is meant to be public, and it only lets a page open the form and take votes.
export default {
scripts: [
{
src: 'https://app.votefirst.app/embed/votefirst.js',
'data-project': 'your-slug',
'data-key': 'your-key',
},
],
};The button
A component holds the button, passes its element to VoteFirst.suggest and unbinds in the cleanup.
Bind the popup in an effect and destroy it on the way out.
The effect runs in the browser only, so the build is not affected.
Docusaurus builds static pages on a server first, where there is no window, and effects do not run during that build. That is why the call belongs in useEffect and not in the body of the component.
In development, React may run an effect twice. The destroy call in the cleanup unbinds the first listener before the second one is added, so one click still opens one dialog.
import { useEffect, useRef } from 'react';
export default function FeedbackButton() {
const button = useRef(null);
useEffect(() => {
const popup = window.VoteFirst.suggest({ trigger: button.current });
return () => popup.destroy();
}, []);
return <button ref={button} className="button button--secondary">Feedback</button>;
}Where it goes
Create docs/feedback.mdx, import the component and render it. Link that page from your sidebar or the footer.
Put the button on a page of its own, then widen it.
The @site alias points at the root of your project.
A single page is the easiest thing to test and to remove. Once it behaves, add the same component to the pages where a reader is most likely to hit a gap, such as the end of a reference page or an error page.
A feedback page also gives you something to link from an issue template or a README, so the people who reach your repository can vote without a GitHub account.
import FeedbackButton from '@site/src/components/FeedbackButton';
# Tell us what to build
Vote on what comes next, or suggest something new.
<FeedbackButton />The board
A navbar item with an href sends readers to the board, where each idea shows its status and its votes.
Link the public board from the navbar.
Readers vote with no account.
The popup collects an idea, and the board is where the idea is counted. A reader who sees an existing card adds a vote, which keeps the list from filling with the same request in ten wordings.
Suggestions wait for your approval before they show, and you can merge two cards that say the same thing. The board address is your own domain if you set one up, which is available on the Free and Pro plans.
navbar: {
items: [
{ href: 'https://feedback.yourapp.com', label: 'Roadmap', position: 'right' },
],
},If it fails
View the page source for the script tag with its two data attributes. Then open the console and read what VoteFirst reports.
Check the script, the origin and the console, in that order.
An unlisted origin is refused with origin_not_allowed.
The key accepts requests only from the origins you list on Share and Embed. Add the address of your live docs, and the address you use for local work, or the form will not load while you build.
If the button does nothing and the script tag is present, the usual cause is a component that ran before the script. With blocking scripts that cannot happen, so look for an async or defer attribute that was added to the object by habit.
What docs readers get
A button that stays correct
It binds when the page appears and unbinds when the reader moves on.
A public place to vote
One navbar link opens a board where ideas show their votes and status.
Nothing to host
The script is a single file served by VoteFirst, so your docs build gains no dependency.
Wire it up in five steps
The config change and the component are the only code.
Create a project
Open a VoteFirst project on the Free plan and copy the slug and key.
Add the script
Put the object with the two data attributes in the scripts list.
Add the component
Create FeedbackButton.js with the effect and the cleanup.
Render it on a page
Import it in a docs page and test the button in the browser.
Link the board
Add the navbar item and set the allowed origins on the key.
What to know before you set this up
- The embed script was read at version 2.8.1, so check the dashboard if a later release changes an option.
- The component needs the script to load first, so keep async and defer off.
- Only listed origins may open the form, including the one you develop on.
- Docusaurus changes its config between major versions, so read its reference for yours.
What docs maintainers ask
Why not use a selector like the plain HTML version?
A selector is resolved once, when you call the function. A button drawn by React after that moment is never found, so the component passes the element itself.
Does the build break because of window?
No. The call sits inside useEffect, and effects do not run while Docusaurus renders the static pages.
Should the script have async or defer?
Leave both off. Docusaurus inserts the tag in the head and, without those attributes, loads it before the page renders, so the component finds window.VoteFirst ready.
What does destroy do?
It removes the click listener from the button and closes the dialog if it is open. Without it, a second call leaves the old listener and one click opens two dialogs.
Can the same component sit on many pages?
Yes. Each instance binds its own button and unbinds when its page is left.
Do readers need a GitHub account to vote?
No. A new board takes votes from anyone, and a cookie tells repeat visitors apart. Required sign in is a setting you can turn on if every vote must name someone.
Can the board use my docs domain?
A subdomain such as feedback.yourapp.com can point at the board on the Free and Pro plans. Lite does not include a custom domain.
Where do new suggestions appear?
In your dashboard, as cards that wait for your approval. A summary email about them reaches the owner once a day at most.
Does it work with the versioned docs feature?
The button is an ordinary component, so it renders on any page that imports it, in any version.
What does it cost to try?
The Free plan covers one project and 100 votes. Lite is $9/mo, Pro is $39/mo, and either one opens with 14 days free and no card.
More ways to add a board
More on React, buttons and the public roadmap.
Feature voting in a React app
The same client in any React project.
A button for any website
Every option the popup takes.
Make a public roadmap
Show readers what comes next.
A board for a Framer site
Custom code or an Embed adds a form and roadmap.
A widget in Next.js
A client component, next/script and the two errors that bite.
Let readers flag docs and product gaps
Start on Free with one project and 100 votes, and try Lite or Pro for 14 days without a card.