Skip to content

feat: debug menu - #66

Merged
pierosavi merged 10 commits into
mainfrom
feat/debug-menu
Oct 26, 2026
Merged

pierosavi merged 10 commits into
mainfrom
feat/debug-menu

Conversation

@PhilipTrauner

@PhilipTrauner PhilipTrauner commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

there are some upcoming features that we'd like to deploy, but not yet make available by default.
...feature flags to the rescue!

this introduces a debug menu that be accessed by tapping 10 times quickly and repeatedly.
it allows toggling feature flags that can be detected in a csr context, through css queries, and during ssr.
flags are persisted as a cookie so they are modifiable and observable from both contexts.

it also introduces the concept of shareable feature enablement URLs that encode which set of features should be enabled as query parameters.
these override the set of currently configured features so complicated "tap 10 times, then enable a + b + c" instructions aren't required when asking someone to test a feature

debug.menu.mov

getting the global Astro context is a bit gnarly, and requires a middleware and some AsyncLocalStorage trickery

/**
* astro global is only available in `.astro` files and middlewares.
* page rendering happens in middleware callback chain
* → introduce global thunk that is set with {@link featureRenderInstall} in ssr context
*
* thunk is eventually populated with help of {@link AsyncLocalStorage}
*/
let renderer: (() => FeatureCookieJar | undefined) | undefined;
/** allows setting {@link renderer} */
export const featureRenderInstall = (
resolve: () => FeatureCookieJar | undefined,
) => {
renderer = resolve;
};

// applies enablement from `?feature=` query parameters and provides render context
const feature = defineMiddleware((context, next) => {
if (context.isPrerendered) {
return next();
}
featureParamApply(context);
return scopeFeature.run(context.cookies, next);
});

ideally this one goes in after being rebased on a feature that needs gating, while also removing the placeholder "foo" feature

@netlify

netlify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for device-database-preview ready!

Name Link
🔨 Latest commit e030c60
🔍 Latest deploy log https://app.netlify.com/projects/device-database-preview/deploys/6adf5b5c912d5fe4028225e9
😎 Deploy Preview https://deploy-preview-66--device-database-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@PhilipTrauner PhilipTrauner mentioned this pull request Oct 22, 2026
Ten quick taps triggered double-tap zoom on mobile and weren't usable
with a keyboard or screen reader. The switches now live on /debug,
which works with any input and can be linked to.
@pierosavi

Copy link
Copy Markdown
Member

Replaced the tap gesture with a no index, not linked /debug page for better accessibility

@pierosavi

pierosavi commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Found a cache bug: the route cache keys on the URL only, but SSR output now depends on the feature cookie. Cached pages (/, /browse, devices, /surveys) served whichever flag state rendered first, both ways. Middleware can't prevent it because the lookup runs before it, and astro dev hides it because the cache is a no-op there.

Fixed in 2cc49f9 with a custom cache provider (src/io/feature-cache.ts). It wraps the memory cache and skips it for requests with the feature cookie or ?feature=, so everyone else is still cached.

Removed the in-process cache, so caching is now left to the CDN (Cloudflare in prod, Netlify in previews). Pages only send Cache-Control headers (src/io/cache-provider.ts), and requests with cookies, auth or ?feature= get no-store. Also removed the Astro.cache.set in SearchBox, which was overriding every page's TTL.

@pierosavi
pierosavi merged commit 1f07bf9 into main Oct 26, 2026
7 checks passed
@pierosavi
pierosavi deleted the feat/debug-menu branch October 26, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants