hunk.code_window:       '@types/react': ^18.0.9
         '@types/use-sync-external-store': ^0.0.3
         '@typescript-eslint/eslint-plugin': 5.36.1
         '@typescript-eslint/parser': 5.36.1
         bunchee: 2.1.5
         eslint: 8.15.0
         eslint-config-prettier: 8.5.0
         eslint-plugin-jest-dom: 4.0.1
         eslint-plugin-react: 7.30.0
         eslint-plugin-react-hooks: 4.5.0
  
hunk.labels: keep keep keep keep replace keep keep keep keep keep
hunk.after_edit:       bunchee: 2.1.6
  
hunk.file_path: pnpm-lock.yaml
hunk.type: replace
file: import { act, screen } from '@testing-library/react'
  import React from 'react'
  import useSWR from 'swr'
  import {
    nextTick as waitForNextTick,
    focusOn,
    createKey,
    renderWithConfig
  } from './utils'
  
  const focusWindow = () => focusOn(window)
  const dispatchWindowEvent = event =>
    act(async () => {
      window.dispatchEvent(new Event(event))
    })
  
  describe('useSWR - offline', () => {
    it('should not revalidate when offline', async () => {
      let value = 0
  
      const key = createKey()
      function Page() {
        const { data } = useSWR(key, () => value++, {
          dedupingInterval: 0
        })
        return <div>data: {data}</div>
      }
  
      renderWithConfig(<Page />)
      // hydration
      screen.getByText('data:')
      // mount
      await screen.findByText('data: 0')
  
      // simulate offline
      await waitForNextTick()
      await dispatchWindowEvent('offline')
  
      // trigger focus revalidation
      await focusWindow()
  
      // should not be revalidated
      screen.getByText('data: 0')
    })
  
    it('should revalidate immediately when becoming online', async () => {
      let value = 0
  
      const key = createKey()
      function Page() {
        const { data } = useSWR(key, () => value++, {
          dedupingInterval: 0
        })
        return <div>data: {data}</div>
      }
  
      renderWithConfig(<Page />)
      // hydration
      screen.getByText('data:')
      // mount
      await screen.findByText('data: 0')
  
      // simulate online
      await waitForNextTick()
      await dispatchWindowEvent('online')
  
      // should be revalidated
      await screen.findByText('data: 1')
    })
  })
  