Remove next/cache usage (use cache, cacheLife, cacheTag, cacheComponents)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F22Ms5Cxam5UHyxaCrtZzu
This commit is contained in:
Rami Bitar
2026-07-29 11:26:23 -04:00
co-authored by Claude Fable 5
parent f23332e42c
commit 1e58ba4ca4
15 changed files with 24 additions and 81 deletions
+4 -11
View File
@@ -1,16 +1,14 @@
import "server-only";
import { analyticsShop as analyticsShopConfig, shop as shopConfig } from "@shared/config";
import { cacheLife, cacheTag } from "next/cache";
import { SHOP_ANALYTICS_QUERY } from "@/lib/queries";
import { staticStorefrontClient } from "@/lib/storefront-static";
/**
* Resolve the shop analytics GID best-effort + non-blocking (engineering.md F1).
* The query runs inside a `'use cache'` cache-point (`cacheLife("hours")`,
* `cacheTag("shop")`) so warm requests resolve instantly. On timeout/error we
* fall back to the config-derived shop GID/name (avoids drift — `@shared/config`
* `analyticsShop.shopId` is already `gid://shopify/Shop/${shop.shopId}`).
* On timeout/error we fall back to the config-derived shop GID/name (avoids
* drift — `@shared/config` `analyticsShop.shopId` is already
* `gid://shopify/Shop/${shop.shopId}`).
*/
export type AnalyticsShop = {
shopId: string;
@@ -24,12 +22,7 @@ const SHOP_FALLBACK: AnalyticsShop = {
shopDescription: null,
};
/** Cache the shop query result for hours (it almost never changes). */
async function fetchShopAnalytics(): Promise<AnalyticsShop> {
"use cache";
cacheLife("hours");
cacheTag("shop");
const { data, errors } = await staticStorefrontClient.graphql(SHOP_ANALYTICS_QUERY);
if (errors) {
console.error("[hydrogen] Root shop query failed", errors);
@@ -42,7 +35,7 @@ async function fetchShopAnalytics(): Promise<AnalyticsShop> {
}
/**
* Best-effort, non-blocking shop analytics resolution. Races the cached query
* Best-effort, non-blocking shop analytics resolution. Races the query
* against a 2000ms timeout; on timeout/error falls back to `@shared/config`.
* Merges the resolved GID/name with the config-derived `analyticsShop`
* metadata (acceptedLanguage/currency/hydrogenSubchannelId).
+2 -3
View File
@@ -14,9 +14,8 @@ import { resolveStorefrontConfig } from "./storefront-config";
* sitemap, related products, shop analytics GID) fetch through this client.
* Only the cart seed uses the per-buyer `getStorefrontClient()`.
*
* Caching lives at the `use cache` boundary (cache-points keyed by serializable
* inputs). The `cache:` option is never passed to `graphql()` — Next native
* data cache + `cacheLife`/`cacheTag` replace the Oxygen sub-request LRU.
* The `cache:` option is never passed to `graphql()` (no Oxygen sub-request
* LRU in this Next.js port).
*/
const requestContext = createShopifyRequestContext({
request: { headers: new Headers() },