Skip to content

Commit 91f6dcd

Browse files
authored
Merge pull request #1216 from ral-facilities/renovate/develop-msw-2.x
Update dependency msw to v2.7.0 (develop)
2 parents ae52c7f + 3c6fdab commit 91f6dcd

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"loglevel": "^1.9.1",
3838
"lz-string": "^1.5.0",
3939
"material-react-table": "^2.13.0",
40-
"msw": "2.6.9",
40+
"msw": "2.7.0",
4141
"react": "^18.3.1",
4242
"react-dom": "^18.3.1",
4343
"react-hook-form": "^7.52.0",

public/mockServiceWorker.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* - Please do NOT serve this file on production.
99
*/
1010

11-
const PACKAGE_VERSION = '2.4.11'
12-
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
11+
const PACKAGE_VERSION = '2.7.0'
12+
const INTEGRITY_CHECKSUM = '00729d72e3b82faf54ca8b9621dbb96f'
1313
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
1414
const activeClientIds = new Set()
1515

@@ -62,7 +62,12 @@ self.addEventListener('message', async function (event) {
6262

6363
sendToClient(client, {
6464
type: 'MOCKING_ENABLED',
65-
payload: true,
65+
payload: {
66+
client: {
67+
id: client.id,
68+
frameType: client.frameType,
69+
},
70+
},
6671
})
6772
break
6873
}
@@ -155,6 +160,10 @@ async function handleRequest(event, requestId) {
155160
async function resolveMainClient(event) {
156161
const client = await self.clients.get(event.clientId)
157162

163+
if (activeClientIds.has(event.clientId)) {
164+
return client
165+
}
166+
158167
if (client?.frameType === 'top-level') {
159168
return client
160169
}
@@ -183,12 +192,26 @@ async function getResponse(event, client, requestId) {
183192
const requestClone = request.clone()
184193

185194
function passthrough() {
186-
const headers = Object.fromEntries(requestClone.headers.entries())
195+
// Cast the request headers to a new Headers instance
196+
// so the headers can be manipulated with.
197+
const headers = new Headers(requestClone.headers)
198+
199+
// Remove the "accept" header value that marked this request as passthrough.
200+
// This prevents request alteration and also keeps it compliant with the
201+
// user-defined CORS policies.
202+
const acceptHeader = headers.get('accept')
203+
if (acceptHeader) {
204+
const values = acceptHeader.split(',').map((value) => value.trim())
205+
const filteredValues = values.filter(
206+
(value) => value !== 'msw/passthrough',
207+
)
187208

188-
// Remove internal MSW request header so the passthrough request
189-
// complies with any potential CORS preflight checks on the server.
190-
// Some servers forbid unknown request headers.
191-
delete headers['x-msw-intention']
209+
if (filteredValues.length > 0) {
210+
headers.set('accept', filteredValues.join(', '))
211+
} else {
212+
headers.delete('accept')
213+
}
214+
}
192215

193216
return fetch(requestClone, { headers })
194217
}

yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5288,7 +5288,7 @@ __metadata:
52885288
loglevel: "npm:^1.9.1"
52895289
lz-string: "npm:^1.5.0"
52905290
material-react-table: "npm:^2.13.0"
5291-
msw: "npm:2.6.9"
5291+
msw: "npm:2.7.0"
52925292
prettier: "npm:3.4.2"
52935293
react: "npm:^18.3.1"
52945294
react-dom: "npm:^18.3.1"
@@ -6449,9 +6449,9 @@ __metadata:
64496449
languageName: node
64506450
linkType: hard
64516451

6452-
"msw@npm:2.6.9":
6453-
version: 2.6.9
6454-
resolution: "msw@npm:2.6.9"
6452+
"msw@npm:2.7.0":
6453+
version: 2.7.0
6454+
resolution: "msw@npm:2.7.0"
64556455
dependencies:
64566456
"@bundled-es-modules/cookie": "npm:^2.0.1"
64576457
"@bundled-es-modules/statuses": "npm:^1.0.1"
@@ -6462,12 +6462,12 @@ __metadata:
64626462
"@open-draft/until": "npm:^2.1.0"
64636463
"@types/cookie": "npm:^0.6.0"
64646464
"@types/statuses": "npm:^2.0.4"
6465-
chalk: "npm:^4.1.2"
64666465
graphql: "npm:^16.8.1"
64676466
headers-polyfill: "npm:^4.0.2"
64686467
is-node-process: "npm:^1.2.0"
64696468
outvariant: "npm:^1.4.3"
64706469
path-to-regexp: "npm:^6.3.0"
6470+
picocolors: "npm:^1.1.1"
64716471
strict-event-emitter: "npm:^0.5.1"
64726472
type-fest: "npm:^4.26.1"
64736473
yargs: "npm:^17.7.2"
@@ -6478,7 +6478,7 @@ __metadata:
64786478
optional: true
64796479
bin:
64806480
msw: cli/index.js
6481-
checksum: 10c0/9489312fac682f56de09e8c6636ed91a37aa313bfa38fc1b365510ed510406c66d1cad66d4300a2c16c02462034ec432775e693dac2e6933bd3e4768b43627ef
6481+
checksum: 10c0/14fb8299dcb6bcf2c6b3777a3127ed6be795a281598394022650b82889f1b70e0ada96559fefead351b18ed5db4e0a3a64367b758dd64f74dea63edc8eb2b551
64826482
languageName: node
64836483
linkType: hard
64846484

@@ -6913,7 +6913,7 @@ __metadata:
69136913
languageName: node
69146914
linkType: hard
69156915

6916-
"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1, picocolors@npm:^1.1.0":
6916+
"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1, picocolors@npm:^1.1.0, picocolors@npm:^1.1.1":
69176917
version: 1.1.1
69186918
resolution: "picocolors@npm:1.1.1"
69196919
checksum: 10c0/e2e3e8170ab9d7c7421969adaa7e1b31434f789afb9b3f115f6b96d91945041ac3ceb02e9ec6fe6510ff036bcc0bf91e69a1772edc0b707e12b19c0f2d6bcf58

0 commit comments

Comments
 (0)