Skip to content

fix(project-details): Memo the date range#113087

Open
nsdeschenes wants to merge 1 commit intomasterfrom
nd/fix-project-details-stop-updating-date-range
Open

fix(project-details): Memo the date range#113087
nsdeschenes wants to merge 1 commit intomasterfrom
nd/fix-project-details-stop-updating-date-range

Conversation

@nsdeschenes
Copy link
Copy Markdown
Contributor

Wrapping these in useMemo so it doesn't cause re-renders and fetching sooooo much data.

@nsdeschenes nsdeschenes marked this pull request as ready for review April 15, 2026 18:57
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 15, 2026
@nsdeschenes nsdeschenes changed the title fix(project-details): Stop updating date range fix(project-details): Memo the date range Apr 15, 2026
gggritso added a commit that referenced this pull request Apr 15, 2026
…ueries (#113100)

Some of the cards on the Project Details pages cause re-fetch cascades:

<img width="799" height="230" alt="Screenshot 2026-04-15 at 4 05 13 PM"
src="https://github.com/user-attachments/assets/3fc21cca-5bb5-4f3b-8180-46ae61078d2b"
/>

<img width="485" height="153" alt="Screenshot 2026-04-15 at 4 06 08 PM"
src="https://github.com/user-attachments/assets/ae787bce-6823-47a2-b1b6-b454a15adde6"
/>

The loop is:

1. Render the component
2. Take the current period (e.g., 14d) and calculate the previous period
to the second (e.g., 2026-03-17T16:15:00 - 2026-04-01T16:15:00)
3. Fetch the data from the previous period using the previous period's
timestamps
4. Data arrives, re-render component
5. Calculate new previous period (e.g., 2026-03-17T16:15:15 -
2026-04-01T16:15:15)

Loop forever. There are a few possible solutions here, including
memoizing the component. Instead, I thought it would be simpler to use
the same approach that some of the other card are using, which is the
`statsPeriodStart` and `statsPeriodEnd` query parameters. Instead of a
timestamp, they specify the start and end as strings, so e.g., `28d` to
`14d` to fetch the previous period. This creates a stable query key for
Tan Stack Query, and stops the refetch. We also could have, for example,
dropped down to a bigger precision (instead of using seconds), but this
seems the tidiest to me.

This is an alternative to
#113087

I'm not sure why those other cards didn't use `statsPeriodStart`, maybe
it wasn't available at the time, or the engineer didn't know about it?

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant