navapbc / template-application-nextjs

Next.js, TypeScript, USWDS, and Storybook template, including CI/CD, for teams at Nava building web applications
Apache License 2.0
10 stars 2 forks source link

Support to set feature flags with query params #328

Closed rylew1 closed 1 month ago

rylew1 commented 2 months ago

Wondering if this project has thought about setting feature flags with query params something.com/mypage?_ff=showFeature:true . If the user loads with this, then that would set a cookie (maybe with a next middleware function).

Maybe it's not needed for the template.


We were just running into an issue - when we see query params, we set the FF cookie with a Next middleware function, but then that FF cookie is not immediately accessible on the same request/response cycle via our server component page.tsx. The server component has access to cookies() from next/headers , but this doesn't carry the FF until the next req/res. (So basically, you have to reload the page and then the cookie is available from the server component page)

Priority

Low (and maybe unnecessary for this project?)

sawyerh commented 2 months ago

@rylew1 Can you share more context about the use case and how AWS Evidently isn't achieving that currently?

I think the query param approach is a remnant from a custom feature flagging approach originally put in place for VT Integrated Benefits, and later carried over to MA PFML, and now other projects.

The templates now provide more sophisticated feature flagging / phased rollout functionality via AWS Evidently instead. AWS Evidently allows you to conditionally enable a feature flag by "entity ID". A common use case is to use a User ID for that, so you can do phased rollouts to a subset of users, but you could also set that value based on a cookie that gets set via a query param, if you want to preserve that behavior.

sequenceDiagram
    participant User
    participant App
    participant Evidently

    User->>App: GET ?features=foo
    App->>App: Set cookie
    App->>Evidently: Evaluate feature, entityID = cookie ? 1 : 0
    Evidently->>App: Return feature flag value
rylew1 commented 1 month ago

IIUC Evidently has the final say on whether that user has access to the feature or not?

Would local also be pointing to Evidently? Evidently would be the source of truth so you can't override it with query params?