Sanity Studio rich text link URL input closes/flickers when clicked
A link popover in the Portable Text editor that closes or flickers when you click into it is most likely a Studio bug, not a mistake in your setup. Upgrading the sanity package to the latest release usually fixes it. If it still happens after upgrading, change the link annotation's href field from url to string, or create links by pasting.
1. Upgrade the Studio
Studio is the sanity npm package, and releases ship up to weekly. Install the latest release instead of using npm update, which stays inside the version range in your package.json:
npm install sanity@latest
npx sanity versions
npx sanity devnpx sanity versions shows whether every Sanity package is current. Update related packages such as @sanity/vision the same way. If the upgrade crosses a major version (v3 → v4 → v5 → v6), read each migration guide first. Studio v4 and later needs Node.js v20.19 or newer. See Upgrading Sanity Studio. After that, redeploy with npx sanity deploy, or push to the branch that deploys your Studio.
2. If it still happens: use string for href
The standard external-link annotation uses a url field (guide):
marks: {
annotations: [
{
name: 'link',
type: 'object',
title: 'External link',
fields: [
{ name: 'href', type: 'url', title: 'URL' },
{ name: 'blank', type: 'boolean', title: 'Open in new tab' },
],
},
],
}The url type renders a browser input with type="url" and always runs uri() validation, which allows only http and https by default (URL type). If that input misbehaves inside the popover, use a plain string field instead. It saves the same kind of value (a string), so your front-end rendering doesn't change:
{ name: 'href', type: 'string', title: 'URL' }If you keep url, you can change what it accepts with your own uri() rule, which replaces the default. For example, rule.uri({scheme: ['http', 'https', 'mailto', 'tel']}) adds more schemes. allowRelative: true allows relative paths and also switches the input to type="text", so the browser stops checking the URL.
3. Shortcut: paste a URL onto selected text
By default, the Portable Text editor turns pasted links into annotations: select some text and paste a URL. This looks for an annotation named link with an href field, which matches the schema above. You don't need to type in the popover at all. If your annotation has a different name, you can write a custom matcher with pasteLink.link(...) (Portable Text editor configuration).
About the cookie and websocket messages
Third-party cookie warnings and "websocket closed before handshake" errors are separate from the popover problem. If the popover still fails on the latest version, open the browser console while you add a link and copy any errors. Search or report them on the sanity-io/sanity GitHub issues, with your browser and the output of npx sanity versions.
Show original thread10 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.