Skip to content

Commit 171f9e0

Browse files
authored
Merge pull request #4263 from riqts/Fix-Polling-Example
Fix Pagination Example for Docs
2 parents 34edf31 + 1770b38 commit 171f9e0

File tree

5 files changed

+42
-25
lines changed

5 files changed

+42
-25
lines changed

examples/query/react/pagination/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
"msw": "^0.40.2",
1717
"react": "^18.1.0",
1818
"react-dom": "^18.1.0",
19-
"react-icons": "3.11.0",
19+
"react-icons": "^5.0.1",
2020
"react-redux": "^9.1.0",
21-
"react-router-dom": "6.3.0",
2221
"react-scripts": "5.0.1"
2322
},
2423
"devDependencies": {

examples/query/react/pagination/public/mockServiceWorker.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
/* eslint-disable */
2+
/* tslint:disable */
3+
14
/**
2-
* Mock Service Worker.
5+
* Mock Service Worker (0.40.2).
36
* @see https://github.com/mswjs/msw
47
* - Please do NOT modify this file.
58
* - Please do NOT serve this file on production.
69
*/
7-
/* eslint-disable */
8-
/* tslint:disable */
910

10-
const INTEGRITY_CHECKSUM = '82ef9b96d8393b6da34527d1d6e19187'
11+
const INTEGRITY_CHECKSUM = '02f4ad4a2797f85668baf196e553d929'
1112
const bypassHeaderName = 'x-msw-bypass'
1213
const activeClientIds = new Set()
1314

@@ -82,11 +83,11 @@ self.addEventListener('message', async function (event) {
8283
}
8384
})
8485

85-
// Resolve the "master" client for the given event.
86+
// Resolve the "main" client for the given event.
8687
// Client that issues a request doesn't necessarily equal the client
8788
// that registered the worker. It's with the latter the worker should
8889
// communicate with during the response resolving phase.
89-
async function resolveMasterClient(event) {
90+
async function resolveMainClient(event) {
9091
const client = await self.clients.get(event.clientId)
9192

9293
if (client.frameType === 'top-level') {
@@ -108,7 +109,7 @@ async function resolveMasterClient(event) {
108109
}
109110

110111
async function handleRequest(event, requestId) {
111-
const client = await resolveMasterClient(event)
112+
const client = await resolveMainClient(event)
112113
const response = await getResponse(event, client, requestId)
113114

114115
// Send back the response clone for the "response:*" life-cycle events.
@@ -220,13 +221,11 @@ async function getResponse(event, client, requestId) {
220221

221222
console.error(
222223
`\
223-
[MSW] Request handler function for "%s %s" has thrown the following exception:
224+
[MSW] Uncaught exception in the request handler for "%s %s":
224225
225-
${parsedBody.errorType}: ${parsedBody.message}
226-
(see more detailed error stack trace in the mocked response body)
226+
${parsedBody.location}
227227
228-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error.
229-
If you wish to mock an error response, please refer to this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
228+
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
230229
`,
231230
request.method,
232231
request.url,
@@ -241,6 +240,12 @@ If you wish to mock an error response, please refer to this guide: https://mswjs
241240

242241
self.addEventListener('fetch', function (event) {
243242
const { request } = event
243+
const accept = request.headers.get('accept') || ''
244+
245+
// Bypass server-sent events.
246+
if (accept.includes('text/event-stream')) {
247+
return
248+
}
244249

245250
// Bypass navigation requests.
246251
if (request.mode === 'navigate') {
@@ -264,11 +269,22 @@ self.addEventListener('fetch', function (event) {
264269

265270
return event.respondWith(
266271
handleRequest(event, requestId).catch((error) => {
272+
if (error.name === 'NetworkError') {
273+
console.warn(
274+
'[MSW] Successfully emulated a network error for the "%s %s" request.',
275+
request.method,
276+
request.url,
277+
)
278+
return
279+
}
280+
281+
// At this point, any exception indicates an issue with the original request/response.
267282
console.error(
268-
'[MSW] Failed to mock a "%s" request to "%s": %s',
283+
`\
284+
[MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
269285
request.method,
270286
request.url,
271-
error,
287+
`${error.name}: ${error.message}`,
272288
)
273289
}),
274290
)

examples/query/react/pagination/src/App.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { Route, Routes } from 'react-router-dom'
21
import { PostsManager } from './features/posts/PostsManager'
32

43
function App() {
54
return (
6-
<Routes>
7-
<Route path="*" element={<PostsManager />} />
8-
</Routes>
5+
<PostsManager />
96
)
107
}
118

examples/query/react/pagination/src/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import App from './App'
44
import { api } from './app/services/posts'
55
import { ChakraProvider } from '@chakra-ui/react'
66

7-
import { BrowserRouter } from 'react-router-dom'
87
import { worker } from './mocks/browser'
98
import { ApiProvider } from '@reduxjs/toolkit/query/react'
109

@@ -14,9 +13,7 @@ worker.start({ quiet: true }).then(() =>
1413
<React.StrictMode>
1514
<ApiProvider api={api}>
1615
<ChakraProvider>
17-
<BrowserRouter>
1816
<App />
19-
</BrowserRouter>
2017
</ChakraProvider>
2118
</ApiProvider>
2219
</React.StrictMode>,

yarn.lock

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5444,9 +5444,8 @@ __metadata:
54445444
msw: "npm:^0.40.2"
54455445
react: "npm:^18.1.0"
54465446
react-dom: "npm:^18.1.0"
5447-
react-icons: "npm:3.11.0"
5447+
react-icons: "npm:^5.0.1"
54485448
react-redux: "npm:^9.1.0"
5449-
react-router-dom: "npm:6.3.0"
54505449
react-scripts: "npm:5.0.1"
54515450
typescript: "npm:~4.9"
54525451
languageName: unknown
@@ -24164,6 +24163,15 @@ __metadata:
2416424163
languageName: node
2416524164
linkType: hard
2416624165

24166+
"react-icons@npm:^5.0.1":
24167+
version: 5.0.1
24168+
resolution: "react-icons@npm:5.0.1"
24169+
peerDependencies:
24170+
react: "*"
24171+
checksum: 10/c4458c643ae32a793ddebc5fa1235c7ec051be1b131205510e8199d15a4c89221a501f95a71fa21c2da93e8dd225290e2e24bb80abd3fb85801e43009e692098
24172+
languageName: node
24173+
linkType: hard
24174+
2416724175
"react-is@npm:^16.13.1, react-is@npm:^16.6.0, react-is@npm:^16.7.0":
2416824176
version: 16.13.1
2416924177
resolution: "react-is@npm:16.13.1"

0 commit comments

Comments
 (0)