fix(studio): open tour ReadMore links in new tab (#4694)

* fix(studio): open tour ReadMore links in new tab

The quick tour "Read more" links navigate away from Studio instead of
opening in a separate tab. Add target="_blank" and rel="noopener
noreferrer" to the ReadMore component so external doc links open in a
new browser tab.

* fix(studio): only open external ReadMore links in new tab

Apply target="_blank" conditionally based on whether the href starts
with "http", so internal links still navigate in the same tab.

* Tighten external-link detection in ReadMore component

Use regex /^https?:\/\// instead of startsWith("http") so the check
requires the full protocol prefix and does not match non-URL strings
that happen to begin with "http".

* Hoist regex to module scope for ReadMore

Move EXTERNAL_URL_RE to top-level constant to satisfy the biome
useTopLevelRegex lint rule and avoid re-creating the RegExp on
every render.

---------

Co-authored-by: Daniel Han <danielhanchen@users.noreply.github.com>
This commit is contained in:
Daniel Han 2026-03-30 23:41:14 -07:00 committed by GitHub
commit fe6609a624
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
const EXTERNAL_URL_RE = /^https?:\/\//;
export function ReadMore({ href = "#" }: { href?: string }) {
const isExternal = EXTERNAL_URL_RE.test(href);
return (
<a
href={href}
target={isExternal ? "_blank" : undefined}
rel={isExternal ? "noopener noreferrer" : undefined}
onClick={(e) => {
if (href === "#") e.preventDefault();
}}