Skip to content

Commit 9a3d48c

Browse files
committed
Update
1 parent 42e1baa commit 9a3d48c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

packages/redux-devtools-rtk-query-monitor/demo/public/mockServiceWorker.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* - Please do NOT modify this file.
88
*/
99

10-
const PACKAGE_VERSION = '2.10.2'
11-
const INTEGRITY_CHECKSUM = 'f5825c521429caf22a4dd13b66e243af'
10+
const PACKAGE_VERSION = '2.11.2'
11+
const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
1212
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
1313
const activeClientIds = new Set()
1414

@@ -71,11 +71,6 @@ addEventListener('message', async function (event) {
7171
break
7272
}
7373

74-
case 'MOCK_DEACTIVATE': {
75-
activeClientIds.delete(clientId)
76-
break
77-
}
78-
7974
case 'CLIENT_CLOSED': {
8075
activeClientIds.delete(clientId)
8176

@@ -94,6 +89,8 @@ addEventListener('message', async function (event) {
9489
})
9590

9691
addEventListener('fetch', function (event) {
92+
const requestInterceptedAt = Date.now()
93+
9794
// Bypass navigation requests.
9895
if (event.request.mode === 'navigate') {
9996
return
@@ -110,23 +107,29 @@ addEventListener('fetch', function (event) {
110107

111108
// Bypass all requests when there are no active clients.
112109
// Prevents the self-unregistered worked from handling requests
113-
// after it's been deleted (still remains active until the next reload).
110+
// after it's been terminated (still remains active until the next reload).
114111
if (activeClientIds.size === 0) {
115112
return
116113
}
117114

118115
const requestId = crypto.randomUUID()
119-
event.respondWith(handleRequest(event, requestId))
116+
event.respondWith(handleRequest(event, requestId, requestInterceptedAt))
120117
})
121118

122119
/**
123120
* @param {FetchEvent} event
124121
* @param {string} requestId
122+
* @param {number} requestInterceptedAt
125123
*/
126-
async function handleRequest(event, requestId) {
124+
async function handleRequest(event, requestId, requestInterceptedAt) {
127125
const client = await resolveMainClient(event)
128126
const requestCloneForEvents = event.request.clone()
129-
const response = await getResponse(event, client, requestId)
127+
const response = await getResponse(
128+
event,
129+
client,
130+
requestId,
131+
requestInterceptedAt,
132+
)
130133

131134
// Send back the response clone for the "response:*" life-cycle events.
132135
// Ensure MSW is active and ready to handle the message, otherwise
@@ -204,7 +207,7 @@ async function resolveMainClient(event) {
204207
* @param {string} requestId
205208
* @returns {Promise<Response>}
206209
*/
207-
async function getResponse(event, client, requestId) {
210+
async function getResponse(event, client, requestId, requestInterceptedAt) {
208211
// Clone the request because it might've been already used
209212
// (i.e. its body has been read and sent to the client).
210213
const requestClone = event.request.clone()
@@ -255,6 +258,7 @@ async function getResponse(event, client, requestId) {
255258
type: 'REQUEST',
256259
payload: {
257260
id: requestId,
261+
interceptedAt: requestInterceptedAt,
258262
...serializedRequest,
259263
},
260264
},

0 commit comments

Comments
 (0)