Skip to content

Conversation

@emisilvacab
Copy link
Contributor

@emisilvacab emisilvacab commented Dec 8, 2025

Description

Fixed channel cache issue in the SlackKit and also applied the same fix for the ms teams.

The problem was that useSlackChannels hook was using SWR for fetching data with a cache key of ["SLACK_CHANNELS", cursor], this key didn’t include the tenantId or knockSlackChannelId. So when the user switched workspaces (different tenant) or disconnected from one slack server and connected to a new one, SWR would return the cached data from the previous connection since the cache key was the same.

Checklist

  • Tests have been added for new features or major refactors to existing features.

Screenshots or videos

Vibecoded a small example to show this by switching tenants

Before

before.mov

After

after.mov

@linear
Copy link

linear bot commented Dec 8, 2025

@changeset-bot
Copy link

changeset-bot bot commented Dec 8, 2025

⚠️ No Changeset found

Latest commit: 2650156

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Dec 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
javascript-ms-teams-connect-example Ready Ready Preview Comment Dec 12, 2025 2:23pm
javascript-nextjs-example Ready Ready Preview Comment Dec 12, 2025 2:23pm
javascript-slack-connect-example Ready Ready Preview Comment Dec 12, 2025 2:23pm
javascript-slack-kit-example Ready Ready Preview Comment Dec 12, 2025 2:23pm

Copy link
Member

@kylemcd kylemcd left a comment

Choose a reason for hiding this comment

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

@emisilvacab We have the swr package installed in react-core. Wondering if we can utilize that to offload some of the caching logic?

@emisilvacab
Copy link
Contributor Author

emisilvacab commented Dec 10, 2025

@kylemcd We're using useSWRInfinite from swr for paginated data. By including tenantId and knockSlackChannelId in the cache key, swr automatically handles cache isolation when these values change.

However, the useEffect I've added is still necessary for edge cases where the access token is revoked or the connection is re-established, scenarios where the cache key remains the same but the cached data is stale. In these cases, we need to manually clear the cache and reset pagination, didn't find something to do this by only using swr.

This is the approach I arrived at but if you have any suggestions or alternative ideas, please let me know.

Copy link
Member

@kylemcd kylemcd left a comment

Choose a reason for hiding this comment

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

Can we cover the missing lines and this should be good to go!

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.64%. Comparing base (36bfd6b) to head (2650156).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #809      +/-   ##
==========================================
+ Coverage   65.51%   66.64%   +1.13%     
==========================================
  Files         189      189              
  Lines        7797     7886      +89     
  Branches      956      999      +43     
==========================================
+ Hits         5108     5256     +148     
+ Misses       2662     2605      -57     
+ Partials       27       25       -2     
Files with missing lines Coverage Δ
...e/src/modules/ms-teams/hooks/useMsTeamsChannels.ts 100.00% <100.00%> (+27.27%) ⬆️
...core/src/modules/ms-teams/hooks/useMsTeamsTeams.ts 100.00% <100.00%> (+34.17%) ⬆️
...t-core/src/modules/slack/hooks/useSlackChannels.ts 100.00% <100.00%> (+28.39%) ⬆️

@emisilvacab emisilvacab requested a review from kylemcd December 12, 2025 14:49
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