Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions apps/marketing/src/lib/site-flags.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import "server-only";

import { FEATURE_FLAGS } from "@superset/shared/constants";
import { unstable_cache } from "next/cache";
import { cacheLife } from "next/cache";
import { posthogServer } from "./posthog-server";

const SITE_DISTINCT_ID = "marketing-site";
const REVALIDATE_SECONDS = 60;

const evaluateSiteFlag = unstable_cache(
async (flag: string) =>
Boolean(
await posthogServer.getFeatureFlag(flag, SITE_DISTINCT_ID, {
sendFeatureFlagEvents: false,
}),
),
["site-flag"],
{ revalidate: REVALIDATE_SECONDS },
);

/** A flag evaluated once for the whole site. Any failure reads as off. */
export async function getSiteFlag(flag: string): Promise<boolean> {
"use cache";
cacheLife({ revalidate: REVALIDATE_SECONDS });
try {
return await evaluateSiteFlag(flag);
return Boolean(
await posthogServer.getFeatureFlag(flag, SITE_DISTINCT_ID, {
sendFeatureFlagEvents: false,
}),
);
} catch (error) {
console.error(`[site-flags] Failed to load ${flag}`, error);
return false;
Comment on lines 20 to 22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Failed flag reads stay cached

If PostHog briefly fails after mobile has launched, this catch returns false from inside the cached function. That off value can remain cached after PostHog recovers, temporarily removing mobile from the sitemap and marking its page noindex. Keep the fallback outside the cache boundary, or avoid caching failed reads.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/marketing/src/lib/site-flags.ts
Line: 20-22

Comment:
**Failed flag reads stay cached**

If PostHog briefly fails after mobile has launched, this catch returns `false` from inside the cached function. That off value can remain cached after PostHog recovers, temporarily removing mobile from the sitemap and marking its page `noindex`. Keep the fallback outside the cache boundary, or avoid caching failed reads.

**Knowledge Base Used:**
- [Marketing product site](https://app.greptile.com/personal-org-6810/-/custom-context/knowledge-base/superset-sh/superset/-/docs/marketing-product-site.md)
- [Marketing routes and content delivery](https://app.greptile.com/personal-org-6810/-/custom-context/knowledge-base/superset-sh/superset/-/docs/marketing-routes-and-content-delivery.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Expand Down
Loading