shadcn.io is not affiliated with official shadcn/ui
CORS Blocked Request Error Block for React
A full-screen page for a cross-origin request the browser blocked: a drawn exchange with the reply's headers and the missing one dashed, the console line in a copy strip, and three fixes with snippets you can copy.
Installation
Overview
Show developers exactly why a request failed and how to fix it, with this CORS error for React with Base UI. It's a whole screen with the page's rails and one band across it. At the start are the headline, one sentence and the Shine Button Read the CORS guide, the only colored control; at the end a framed drawing of the exchange: the page's origin and the server's, an arrow each way, and the reply's headers as a real table with Access-Control-Allow-Origin as a dashed row that says Not sent. Under them the browser's console line sits in a strip with a Copy Button, and three fix cells on shared hairlines hold the ways out: add the header, use a server-side proxy, use a dev-server proxy, each with its snippet and a button that really copies it. The band's rules and the drawing's frame come from Guides, and the entrance is CSS only. For an API console, a docs site or any developer tool.
FAQ
Does it send a request, and what really gets copied?
It sends nothing: the origins end in .test, the headers and the console line are typed in the file, and the page only describes a failure. The copy buttons are real: each one writes its snippet (or the console line) to the clipboard, and says Copied or Couldn't copy through its own polite status. Swap the hosts and snippets for yours in PAGE, API, HEADERS, CONSOLE and FIXES.
Why does the browser throw the reply away?
Because a page may only read a reply from another origin when that server says so, with an Access-Control-Allow-Origin header naming the page's origin. The request went out and the server answered, but without the header, so the browser blocks the page from seeing the response. It is a rule of the browser, not of the server, which is why a command-line request to the same address works.
Which of the three fixes should I use?
Adding the header on the API is the real fix when you own it: name the exact origin, and avoid a star on endpoints that use cookies or tokens. A server-side proxy suits APIs you don't control, because your server calls them and the browser only sees your origin. A dev-server proxy is only for building locally; it does nothing in production. You cannot turn CORS off in the browser for your visitors.
How can you tell the missing header without color?
It is a dashed row with a cross and the words Not sent, while the headers that arrived are solid rows with values. The console line has a heavy edge at its start and a Blocked label above it. The only status color is the cross.
Is it usable with a keyboard and a screen reader?
Tab reaches Read the CORS guide, the console's copy button and each fix's copy button, in that order, each named for what it copies. The headers are a real table with a caption and row headers, the drawing's two origins are decorative (the console line below names both of them in text), and the code is plain text that you can select.
What changes on a phone?
The headline and the guide button come first, then the drawing and the headers, then the console line cut to two lines (the copy button still copies the whole line), then the three fixes stacked, each with its snippet. The explanations under each fix's name stay for screen readers and are hidden from sight, and nothing scrolls sideways down to 320 px.
Related
- Pro
API Uptime Strips Error
Server and outagesA full-screen outage page for an API host: the display 503, a notify-me form that saves in the page, and four APIs as rows of thirty day-cells with a shape and a word for today and an uptime counted from the minutes.
- Pro
A full-screen warning for a site whose certificate expired: a drawn open padlock, Back to safety, and an Advanced disclosure with the certificate chain, the error code to copy and an unsafe route behind a checkbox.
- Pro
DNS Lookup Chain Error
NetworkA full-screen page for an address that can't be found: an editable address, a Run the check button, and the lookup drawn as five hops that walk one at a time and stop at the one with no answer.
- Pro
Database Backoff Schedule Error
Server and outagesA full-screen page for a database that refuses connections: Retry now and a switch that retries by itself on a press-started countdown, four pool cells and the backoff schedule drawn to scale.
- Pro
Services Status Error
Server and outagesA hosting platform's status as one framed panel: six services with a shape and a word for each state, a summary counted from them, an Affected only filter that holds the panel's height, and a Refresh status button.
- Pro
Connection Fallback Error
NetworkA full-screen page for a live connection that dropped and fell back: three signal bars, three transport rows with a shape and a word each, Reconnect now as a short scripted attempt, and a Keep using polling toggle.