Skip to content

Feast "Saved from web" recipe state - #16412

Open
andresilva-guardian wants to merge 30 commits into
mainfrom
afs/save-feast-recipe-from-the-web
Open

Feast "Saved from web" recipe state#16412
andresilva-guardian wants to merge 30 commits into
mainfrom
afs/save-feast-recipe-from-the-web

Conversation

@andresilva-guardian

@andresilva-guardian andresilva-guardian commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What does this change?

We have added support for checking and updating whether a recipe has already been saved to a reader's Feast "Saved from web" list.

On the client, we added src/lib/feast/savedFromWeb.ts with getFeastSavedFromTheWebRecipes and addFeastRecipeToSavedFromWebList, which call a proxy route at /api/feast-saved-recipes that forwards the reader's bearer token straight through to the Feast API's /v2/saved-from-web endpoints (GET, to check which recipe ids are saved; PUT /:recipeId, to add a recipe to the list). We go through a server-side proxy rather than calling the Feast API directly from the browser, since this sidesteps needing Feast API-side CORS configuration for browser origins.

That proxy route is implemented in Frontend, not DCR. We originally added it as a DCR Express route, but DCR isn't on the reader-facing origin (www.theguardian.com / m.code.dev-theguardian.com) — it's only ever called internally by Frontend for rendering. A route living solely in DCR is unreachable by a same-origin browser fetch(), so it was removed from DCR and reimplemented in Frontend instead, which does own that origin. See [frontend#TODO] for the Frontend-side implementation of /api/feast-saved-recipes.

getFeastSavedFromTheWebRecipes caches in-flight and resolved requests by user id and recipe ids, so that when multiple FeastContextualNudge islands hydrate on the same page, only one network request is made for the whole batch of recipe ids rather than one per nudge.

We updated ArticleRenderer to compute the full list of recipe ids that will get a nudge on the page upfront and pass it to every FeastContextualNudge instance as allNudgeRecipeIds. Each FeastContextualNudge then uses this, together with the signed-in reader's id and access token, to fetch whether its own recipe is already saved, and passes an isRecipeSaved flag through to the Braze banner.

We also added a SaveFeastRecipeById message type to BrazeBannersSystem, so a Braze banner can ask DCR to save a Feast recipe to the reader's list on their behalf. This calls addFeastRecipeToSavedFromWebList with the reader's access token, logs the outcome, and posts the result back to the banner along with a custom Braze event (braze_banner_save_feast_recipe).

Why?

We want Feast contextual nudges (and the Braze banners they render) to reflect whether a reader has already saved a given recipe from the web, and to let readers save a recipe directly from the banner. Batching the "is this saved?" check across all nudges on a page, and caching it, avoids making a separate network request per nudge when several appear on the same article.

Dependencies

⚠️ This PR alone is not sufficient to make the feature work end-to-end: it depends on a companion change in guardian/frontend that implements the /api/feast-saved-recipes proxy route (GET + PUT). Until that's merged and deployed, getFeastSavedFromTheWebRecipes / addFeastRecipeToSavedFromWebList will 404, and FeastContextualNudge will simply behave as if no recipe is ever saved (graceful fallback, no crash).

How has this change been tested?

Screenshots

Before After
before after

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

@andresilva-guardian
andresilva-guardian changed the base branch from main to afs/feast-contextual-nudge-braze-banners July 20, 2026 09:17
@andresilva-guardian andresilva-guardian added the feature Departmental tracking: work on a new feature label Jul 21, 2026
@andresilva-guardian andresilva-guardian changed the title Afs/save feast recipe from the web Feast "Saved from web" recipe state Jul 21, 2026
@andresilva-guardian
andresilva-guardian marked this pull request as ready for review July 21, 2026 15:06
@andresilva-guardian
andresilva-guardian requested review from a team as code owners July 21, 2026 15:06
@github-actions

Copy link
Copy Markdown

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

…722105844 in package.json and pnpm-lock.yaml
Base automatically changed from afs/feast-contextual-nudge-braze-banners to main July 27, 2026 10:44
@andresilva-guardian

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in 4 files:

  • FeastContextualNudge.island.tsx — kept submitComponentEvent import from main, kept allNudgeRecipeIds prop + AB test logic + isRecipeSaved state from this branch, removed the duplicate Braze banner block from the conflict
  • FeastContextualNudge.stories.tsx — kept allNudgeRecipeIds in args
  • ArticleRenderer.tsx — kept sectionsWithNudgeIndex + allNudgeRecipeIds computation, kept allNudgeRecipeIds prop
  • BrazeBannersSystem.tsx — adopted main's ALL_PLACEMENT_IDS/placementsToRequest improvements to refreshBanners, kept this branch's SaveFeastRecipeById message type and handler

TypeScript passes with no errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants