Skip to content

Commit

Permalink
fetch on initial mount to reduce client latency
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed May 6, 2024
1 parent 30fddab commit 2703967
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/src/resources/__tests__/useNotifyService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ describe('useNotifyService', () => {
vi.clearAllMocks()
})

it('should trigger a subscribe action on a successful initial mount', () => {
it('should trigger an HTTP refetch and subscribe action on a successful initial mount', () => {
renderHook(() =>
useNotifyService({
topic: MOCK_TOPIC,
setRefetch: mockHTTPRefetch,
options: MOCK_OPTIONS,
} as any)
)
expect(mockHTTPRefetch).toHaveBeenCalledWith('once')
expect(mockDispatch).toHaveBeenCalledWith(
notifySubscribeAction(MOCK_HOST_CONFIG.hostname, MOCK_TOPIC)
)
Expand Down
2 changes: 2 additions & 0 deletions app/src/resources/useNotifyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function useNotifyService<TData, TError = Error>({

React.useEffect(() => {
if (shouldUseNotifications) {
// Always fetch on initial mount to keep latency as low as possible.
setRefetch('once')
appShellListener({
hostname,
topic,
Expand Down

0 comments on commit 2703967

Please sign in to comment.