Skip to content

ref(whats-new): Single data-fetch source and fix mark-seen edge cases#110269

Open
JonasBa wants to merge 4 commits intomasterfrom
jb/refs/whatsnew
Open

ref(whats-new): Single data-fetch source and fix mark-seen edge cases#110269
JonasBa wants to merge 4 commits intomasterfrom
jb/refs/whatsnew

Conversation

@JonasBa
Copy link
Member

@JonasBa JonasBa commented Mar 9, 2026

Add test coverage to whats new button and move the fetch handler to the parent component. This is in preparation to making the change to broadcasts so that the endpoint always returns the last 3 broadcasts, regardless if they were seen or not which will prevent the empty state from being shown (poor ux given the importance of the primary sidebar button)

Requires #110286

Move useFetchBroadcasts() from WhatsNewContent into the parent
PrimaryNavigationWhatsNew so broadcasts and isPending are fetched
once and passed down as props. This removes the duplicate hook call
and separates the loading state from the empty state, which were
previously conflated via broadcasts.length === 0.

Also fix two related bugs:
- Skip the mark-seen PUT request when unseenPostIds is empty, preventing
  a spurious request with an empty id list when all broadcasts are seen
- Fix the onSuccess cache update fallback from [] to undefined so a
  missing cache entry is not replaced with an empty array

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 9, 2026
@JonasBa JonasBa marked this pull request as ready for review March 9, 2026 23:12
@JonasBa JonasBa requested a review from a team March 9, 2026 23:12
setApiQueryData<Broadcast[]>(
queryClient,
makeBroadcastsQueryKey({organization}),
data => (data ? data.map(item => ({...item, hasSeen: true})) : [])
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixes accidental cache write using an empty value

const {isPending, data: broadcasts = []} = useFetchBroadcasts();

useEffect(() => {
if (unseenPostIds.length === 0) {
Copy link
Member Author

Choose a reason for hiding this comment

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

prevent post calls when all posts have been seen

Pass ?limit=3 to the org broadcasts endpoint so the server guarantees
at least 3 results, backfilling with other active broadcasts when needed.

Removes the client-side assumption that the server always returns enough
broadcasts, and updates test mocks to match the new query param.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@JonasBa
Copy link
Member Author

JonasBa commented Mar 10, 2026

@cursoragent update this PR to use the show="latest" and limit=3 as the query param options. The relevant backend changes can be observed in #110323

@cursor
Copy link
Contributor

cursor bot commented Mar 10, 2026

Summary

I've successfully updated this PR to use the new query parameters show="latest" and limit=3 as requested. Here's what was changed:

Changes Made:

  1. Updated the implementation (whatsNew.tsx):

    • Modified makeBroadcastsQueryKey() to include both show: 'latest' and limit: '3' in the query parameters
    • Used string values for consistency with URL query parameters
  2. Updated all test mocks (whatsNew.spec.tsx):

    • Updated 9 test cases to include both show: 'latest' and limit: '3' in their mock query matchers
    • Fixed the type mismatch issue that was flagged by Bugbot (query parameters are now consistently strings)
  3. Testing & Validation:

    • All 9 tests pass successfully
    • Pre-commit hooks pass (ESLint, Prettier, etc.)
    • Changes committed and pushed to the jb/refs/whatsnew branch

These changes align with the backend PR #110323, which adds support for the show=latest parameter to fetch only active broadcasts and the limit parameter to control the number of results returned (defaulting to 3).

Open in Web Open in Cursor 

- Add show='latest' query parameter to fetch only active broadcasts
- Add limit='3' to explicitly limit results to 3 broadcasts
- Update all test mocks to match the new query parameters
- Fixes type mismatch in mock query matching by using string values

Co-authored-by: Jonas <JonasBa@users.noreply.github.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.

3 participants