Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Improve site input UI

Blue Mouse8f56469a3de8
diff --git a/web/app/components/marketing/HeroSignupForm.tsx b/web/app/components/marketing/HeroSignupForm.tsx
index ee69cc2e7..68c774783 100644
--- a/web/app/components/marketing/HeroSignupForm.tsx
+++ b/web/app/components/marketing/HeroSignupForm.tsx
@@ -51,9 +51,13 @@ const HeroSignupForm = () => {
return (
<form
onSubmit={handleSubmit}
- className='mt-8 flex w-full max-w-xl flex-col items-stretch gap-3 sm:flex-row'
+ className='mt-8 flex w-full max-w-sm flex-col items-stretch gap-3'
>
- <div className='flex h-12 flex-1 items-center rounded-md bg-white/10 pl-3 ring-1 ring-white/25 backdrop-blur-md transition-colors focus-within:bg-white/15 focus-within:ring-2 focus-within:ring-white/60'>
+ {/* The same shape as <Input>, in the hero's palette: inset ring, brighter
+ on hover, doubled on focus. The wrapper owns the focus treatment, so
+ the inner input drops both its outline and the blue ring
+ @tailwindcss/forms puts on every bare input. */}
+ <div className='flex h-12 items-center rounded-md bg-white/10 pl-3 ring-1 ring-white/20 backdrop-blur-md transition-shadow duration-150 ease-out ring-inset focus-within:ring-2 focus-within:ring-white hover:ring-white/40'>
<span className='grid size-5 shrink-0 place-items-center text-gray-200'>
<FaviconGlyph value={website} className='size-5' />
</span>
@@ -64,12 +68,12 @@ const HeroSignupForm = () => {
aria-label={t('main.yourWebsite')}
autoComplete='url'
inputMode='url'
- className='h-full min-w-0 flex-1 border-0 bg-transparent px-2.5 text-base text-white outline-none placeholder:text-gray-300'
+ className='h-full min-w-0 flex-1 border-0 bg-transparent px-3 text-base text-white outline-hidden placeholder:text-gray-300 focus:ring-0'
/>
</div>
<button
type='submit'
- className='inline-flex h-12 shrink-0 items-center justify-center rounded-md bg-white px-5 text-slate-950 shadow-lg ring-1 shadow-slate-950/20 ring-white/30 transition-colors hover:bg-gray-100'
+ className='inline-flex h-12 items-center justify-center rounded-md bg-white px-5 text-slate-950 shadow-lg ring-1 shadow-slate-950/20 ring-white/30 transition-colors hover:bg-gray-100'
>
<span className='text-center text-base font-semibold'>
{t('main.addMyWebsite')}
diff --git a/web/app/pages/Onboarding/Onboarding.tsx b/web/app/pages/Onboarding/Onboarding.tsx
index 8650d2b70..6d930d939 100644
--- a/web/app/pages/Onboarding/Onboarding.tsx
+++ b/web/app/pages/Onboarding/Onboarding.tsx
@@ -921,6 +921,7 @@ const Onboarding = () => {
/>
<Input
name='websiteUrl'
+ variant='website'
label={t('project.settings.websiteUrl')}
hint={t('project.settings.websiteUrlHint')}
value={projectWebsiteUrl}
diff --git a/web/app/routes/_index.tsx b/web/app/routes/_index.tsx
index 70381f966..beacbf289 100644
--- a/web/app/routes/_index.tsx
+++ b/web/app/routes/_index.tsx
@@ -422,31 +422,12 @@ const HeroCTA = () => {
const { t } = useTranslation('common')
const { heroVariant } = useLoaderData<typeof loader>()
- const liveDemoButton = (
- <Button
- to={LIVE_DEMO_URL}
- linkProps={{
- target: '_blank',
- rel: 'noopener noreferrer',
- }}
- variant='secondary'
- size='xl'
- className='flex h-12 items-center justify-center border-white/25 bg-white/10 px-5 text-center text-base font-semibold text-white shadow-none ring-white/25 backdrop-blur-md hover:bg-white/20 dark:border-white/25 dark:bg-white/10 dark:text-white dark:hover:bg-white/20'
- aria-label={`${t('main.seeLiveDemo')} (opens in a new tab)`}
- >
- {t('common.liveDemo')}
- </Button>
- )
-
+ // The variant arm is deliberately a single path: one field, one button. The
+ // live demo link stays in the control arm (and in the header) - putting a
+ // second CTA next to the field is exactly the split attention we're testing
+ // our way out of.
if (heroVariant === HERO_SIGNUP_EXPERIMENT.siteInput) {
- return (
- <div className='flex w-full flex-col items-center'>
- <HeroSignupForm />
- <div className='mt-3 flex w-full flex-col items-stretch sm:w-auto'>
- {liveDemoButton}
- </div>
- </div>
- )
+ return <HeroSignupForm />
}
return (
@@ -466,7 +447,19 @@ const HeroCTA = () => {
</span>
<ArrowRightIcon className='mt-[1px] ml-1 h-4 w-5' />
</Link>
- {liveDemoButton}
+ <Button
+ to={LIVE_DEMO_URL}
+ linkProps={{
+ target: '_blank',
+ rel: 'noopener noreferrer',
+ }}
+ variant='secondary'
+ size='xl'
+ className='flex h-12 items-center justify-center border-white/25 bg-white/10 px-5 text-center text-base font-semibold text-white shadow-none ring-white/25 backdrop-blur-md hover:bg-white/20 dark:border-white/25 dark:bg-white/10 dark:text-white dark:hover:bg-white/20'
+ aria-label={`${t('main.seeLiveDemo')} (opens in a new tab)`}
+ >
+ {t('common.liveDemo')}
+ </Button>
</div>
)
}
diff --git a/web/app/routes/api.favicon.ts b/web/app/routes/api.favicon.ts
index 331cdbb18..3d8fb62cc 100644
--- a/web/app/routes/api.favicon.ts
+++ b/web/app/routes/api.favicon.ts
@@ -31,28 +31,39 @@ export async function loader({ request }: LoaderFunctionArgs) {
return Response.redirect(new URL(FALLBACK_ICO, url.origin).toString(), 302)
}
- try {
- const upstream = await fetch(
- `https://icons.duckduckgo.com/ip3/${encodeURIComponent(domain)}.ico`,
- { signal: AbortSignal.timeout(4000) },
- )
-
- if (!upstream.ok || !upstream.body) {
- return Response.redirect(
- new URL(FALLBACK_ICO, url.origin).toString(),
- 302,
- )
- }
+ // Google first: it flattens icons onto their own background, so a site whose
+ // favicon is a bare transparent glyph (stripe.com is white, vercel.com is
+ // black) still reads on whatever surface we drop it on. DuckDuckGo serves the
+ // raw file, which is better quality but disappears against half our
+ // backgrounds - so it's the second opinion, for domains Google misses.
+ const sources = [
+ `https://www.google.com/s2/favicons?domain=${encodeURIComponent(domain)}&sz=64`,
+ `https://icons.duckduckgo.com/ip3/${encodeURIComponent(domain)}.ico`,
+ ]
- return new Response(upstream.body, {
- status: 200,
- headers: {
- 'Content-Type': upstream.headers.get('Content-Type') || 'image/x-icon',
- 'Cache-Control': `public, max-age=${CACHE_TTL}, stale-while-revalidate=${STALE_TTL}`,
- Vary: VARY,
- },
- })
- } catch {
- return Response.redirect(new URL(FALLBACK_ICO, url.origin).toString(), 302)
+ for (const source of sources) {
+ try {
+ const upstream = await fetch(source, {
+ signal: AbortSignal.timeout(4000),
+ })
+
+ if (!upstream.ok || !upstream.body) {
+ continue
+ }
+
+ return new Response(upstream.body, {
+ status: 200,
+ headers: {
+ 'Content-Type':
+ upstream.headers.get('Content-Type') || 'image/x-icon',
+ 'Cache-Control': `public, max-age=${CACHE_TTL}, stale-while-revalidate=${STALE_TTL}`,
+ Vary: VARY,
+ },
+ })
+ } catch {
+ // Timeout or network blip - try the next source.
+ }
}
+
+ return Response.redirect(new URL(FALLBACK_ICO, url.origin).toString(), 302)
}
diff --git a/web/app/ui/Input.tsx b/web/app/ui/Input.tsx
index a6dea7e4b..133091481 100644
--- a/web/app/ui/Input.tsx
+++ b/web/app/ui/Input.tsx
@@ -7,6 +7,7 @@ import {
import cx from 'clsx'
import { EyeIcon, EyeSlashIcon } from '@phosphor-icons/react'
import React, { memo, useState } from 'react'
+import FaviconGlyph from './FaviconGlyph'
import { Text } from './Text'
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
@@ -18,12 +19,23 @@ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
error?: string | null
disabled?: boolean
readOnly?: boolean
+ /**
+ * `website` turns the field into a "your website" input: the leading glyph is
+ * a globe that swaps for the site's live favicon as soon as what's typed
+ * looks like a domain, the same affordance the landing hero uses. Works
+ * controlled or uncontrolled.
+ */
+ variant?: 'default' | 'website'
classes?: {
input?: string
leadingIcon?: string
}
}
+const toStringValue = (
+ value: React.InputHTMLAttributes<HTMLInputElement>['value'],
+) => (value === undefined || value === null ? '' : String(value))
+
// TODO: Merge className and classes
const Input = React.forwardRef<HTMLInputElement, InputProps>(
@@ -37,6 +49,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
error,
disabled,
readOnly,
+ variant = 'default',
classes,
...rest
},
@@ -45,9 +58,31 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
const isError = Boolean(error)
const type = rest.type || 'text'
const isPassword = type === 'password'
- const hasLeadingIcon = Boolean(leadingIcon)
+ const isWebsite = variant === 'website'
const [showPassword, setShowPassword] = useState(false)
+ // The favicon needs the current value. Mirror it internally so the variant
+ // works uncontrolled too, and prefer the prop whenever there is one.
+ const [uncontrolledValue, setUncontrolledValue] = useState(() =>
+ toStringValue(rest.defaultValue as InputProps['value']),
+ )
+ const websiteValue =
+ rest.value === undefined ? uncontrolledValue : toStringValue(rest.value)
+
+ const resolvedLeadingIcon =
+ leadingIcon ??
+ (isWebsite ? (
+ <FaviconGlyph value={websiteValue} className='size-4.5' />
+ ) : null)
+ const hasLeadingIcon = Boolean(resolvedLeadingIcon)
+
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ if (isWebsite && rest.value === undefined) {
+ setUncontrolledValue(event.target.value)
+ }
+ rest.onChange?.(event)
+ }
+
const { type: _type, ...restWithoutType } = rest
const inputElement = (
@@ -74,9 +109,12 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
invalid={isError}
aria-invalid={isError || undefined}
{...restWithoutType}
+ onChange={handleChange}
autoComplete={
- rest.autoComplete ?? (isPassword ? 'current-password' : undefined)
+ rest.autoComplete ??
+ (isPassword ? 'current-password' : isWebsite ? 'url' : undefined)
}
+ inputMode={rest.inputMode ?? (isWebsite ? 'url' : undefined)}
type={isPassword && showPassword ? 'text' : type}
/>
)
@@ -92,7 +130,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
classes?.leadingIcon,
)}
>
- {leadingIcon}
+ {resolvedLeadingIcon}
</div>
) : null}
{inputElement}
diff --git a/web/app/utils/experiments.ts b/web/app/utils/experiments.ts
index 450fbcde7..6adee5dcc 100644
--- a/web/app/utils/experiments.ts
+++ b/web/app/utils/experiments.ts
@@ -1,8 +1,7 @@
/**
* Variant keys for the server-side A/B tests we run on ourselves via Swetrix
* experiments. These must match the variant keys of the matching experiment in
- * the Swetrix dashboard exactly; the experiment IDs themselves live in
- * `analytics.server.ts` (they're only ever read inside loaders).
+ * the Swetrix dashboard exactly.
*
* Variants are resolved in the loader, so the page is server-rendered in its
* final form - no flash of the control arm, no client-side flicker.