feat: add Client Hints support for improved cold-start detection#113
Open
superbiche wants to merge 1 commit into
Open
feat: add Client Hints support for improved cold-start detection#113superbiche wants to merge 1 commit into
superbiche wants to merge 1 commit into
Conversation
Adds opt-in HTTP Client Hints (Sec-CH-UA-Mobile, Sec-CH-Viewport-Width) to the detection chain, improving first-visit accuracy for tablets, split-screen, and iPads in desktop mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the Client Hints detection proposed in #110, extending the existing
utils.tsas suggested by @mvrlin.clientHints: true | { viewportWidth, critical }in module configclientHintsoption — fully backward compatibleWhat's included
types.ts: newClientHintsOptionstype +clientHintsproperty onViewportOptionsutils.ts:Sec-CH-Viewport-Width(pixel-accurate) andSec-CH-UA-Mobile(default on Chromium) detection, plusresolveBreakpointFromWidth()helperplugin.server.ts: setsAccept-CH/Critical-CHresponse headers whenviewportWidthis enabledDesign choices worth noting
This implementation takes a different approach from #112:
detectBreakpoint()instead of rewriting it — no API surface changes, no removed functionsSec-CH-Viewport-Widthmaps to configured breakpoints using theminWidth/maxWidthfeature mode, rather than a hardcoded thresholddefaultBreakpoints:Sec-CH-UA-Mobilemaps through the existing config (e.g.mobile → "sm") instead of returning raw device type stringsAccept-CHandCritical-CHresponse header negotiation, which is required for browsers to sendSec-CH-Viewport-Widthimport()for chunk splitting~98 lines added across 3 files.
Test plan
clientHintsconfig)clientHints: true— confirmSec-CH-UA-Mobiledetection works on ChromiumclientHints: { viewportWidth: true }— confirmAccept-CHheader is set and width-based detection resolves to correct breakpointclientHints: { viewportWidth: true, critical: true }— confirmCritical-CHheader is set