Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #1795]: Fix feature flag refresh bug #1863

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

rylew1
Copy link
Collaborator

@rylew1 rylew1 commented Apr 26, 2024

Summary

Fixes #1795

Time to review: 5 min

Changes proposed

  • update isFeatureEnabled to have query params override the currently set cookie (which can become out of date)
  • update isFeatureDisabled
  • Update a test to cover this condition

Context

The feature flag is set from a Next middleware function in FeatureFlagsManager. Unfortunately when this is set, it's not setting a value that's accessible to other code in the same request/response cycle (like the server component page) . The server component page has access to next/headers cookies, but not from the ones set from the middleware function.

So we can just pass the SearchParams that the server component has into the isFeatureEnabled (and isFeatureDisabled) for now. Acknowledging that there might be multiple ways to do this.

Screen.Recording.2024-04-26.at.3.33.48.PM.mov

@@ -39,7 +39,8 @@ export function generateMetadata() {

export default async function Search({ searchParams }: ServerPageProps) {
const ffManager = new FeatureFlagsManager(cookies());
if (!ffManager.isFeatureEnabled("showSearchV0")) {

if (ffManager.isFeatureDisabled("showSearchV0", searchParams)) {
Copy link
Collaborator Author

@rylew1 rylew1 Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch this to isFeatureDisabled - reads a little better when the intent is to check if we should redirect to the NotFound page

Copy link
Collaborator

@acouch acouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, tested locally.

@@ -6,6 +6,7 @@ import { NextRequest, NextResponse } from "next/server";

import { CookiesStatic } from "js-cookie";
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
import { ServerSideSearchParams } from "../types/searchRequestURLTypes";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope comment. the mixing of relative paths gave me pause. i created a ticket to address for the frontend: #1868 , so this is fine for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can take a look at making imports more consistent

@rylew1 rylew1 merged commit cf0f378 into main Apr 29, 2024
9 checks passed
@rylew1 rylew1 deleted the rylew/1795-fix-ff-requiring-2-refresh branch April 29, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Fix FF requiring 2 refresh
2 participants