Skip to content

fix: prevent logging the retry message many times #382

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

Merged
merged 4 commits into from
Apr 10, 2025

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Apr 9, 2025

Resolves: N/A

Description

This PR prevents the client from logging its retry message many times in succession. The retry message is printed when an invalid or expired ref is tried.

The logger's history is tracked at the module level and will be shared across multiple clients.

The history will not be shared across multiple processes, such as during the different stages of a Next.js build. Still, this PR will reduce the total number of logs.

This PR also adds a [@prismicio/client] prefix to the retry message, consistent with the client's other logged messages.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

This is an example log when building a Next.js website that has a cached expired ref.

Before

$ npm run build

> [email protected] build
> next build

   ▲ Next.js 15.1.6

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types
   Collecting page data  ..The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
 ✓ Collecting page data
The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
 ✓ Generating static pages (9/9)
 ✓ Collecting build traces
 ✓ Finalizing page optimization

After

$ npm run build

> [email protected] build
> next build

   ▲ Next.js 15.1.6

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types
   Collecting page data  ...[@prismicio/client] The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
 ✓ Collecting page data
[@prismicio/client] The ref (Z7zeQREAACIAd_Dg) was expired. Now retrying with the latest master ref (Z_bKXBEAACMA-ETo). If you were previewing content, the response will not include draft content.
 ✓ Generating static pages (9/9)
 ✓ Collecting build traces
 ✓ Finalizing page optimization

How to QA 1

  1. In a Next.js Prismic website, delete the .next folder, which includes the fetch() cache.
  2. Build the Next.js website.
  3. Publish a change to the Prismic repo.
  4. Rebuild the Next.js website. Notice the logs.

Perform the above steps once with the latest published version, then again with this PR.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.84%. Comparing base (5966b61) to head (609a892).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #382   +/-   ##
=======================================
  Coverage   99.84%   99.84%           
=======================================
  Files          76       77    +1     
  Lines        3210     3230   +20     
  Branches      658      661    +3     
=======================================
+ Hits         3205     3225   +20     
  Misses          5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@lihbr lihbr left a comment

Choose a reason for hiding this comment

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

LGTM but I believe there's one issue with the throttling :)

@angeloashmore angeloashmore merged commit c2bcf4b into master Apr 10, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants