Skip to content

Commit e4e6169

Browse files
fix: fix MSW load (riccardoperra#376)
* fix: fix MSW service worker * fix css bundle invalid syntax
1 parent a1fdf94 commit e4e6169

File tree

4 files changed

+17
-116
lines changed

4 files changed

+17
-116
lines changed

apps/codeimage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@types/downloadjs": "^1.4.3",
2222
"cross-env": "^7.0.3",
2323
"https-localhost": "^4.7.1",
24-
"msw": "^0.47.3",
24+
"msw": "^0.47.4",
2525
"prettier": "^2.6.2",
2626
"rimraf": "^3.0.2",
2727
"sass": "^1.52.1",

apps/codeimage/public/mockServiceWorker.js

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
/* tslint:disable */
33

44
/**
5-
* Mock Service Worker (0.43.1).
5+
* Mock Service Worker (0.47.4).
66
* @see https://github.com/mswjs/msw
77
* - Please do NOT modify this file.
88
* - Please do NOT serve this file on production.
99
*/
1010

11-
const INTEGRITY_CHECKSUM = 'c9450df6e4dc5e45740c3b0b640727a2'
11+
const INTEGRITY_CHECKSUM = 'b3066ef78c2f9090b4ce87e874965995'
1212
const activeClientIds = new Set()
1313

1414
self.addEventListener('install', function () {
@@ -200,7 +200,7 @@ async function getResponse(event, client, requestId) {
200200

201201
function passthrough() {
202202
// Clone the request because it might've been already used
203-
// (i.e. its body has been read and sent to the cilent).
203+
// (i.e. its body has been read and sent to the client).
204204
const headers = Object.fromEntries(clonedRequest.headers.entries())
205205

206206
// Remove MSW-specific request headers so the bypassed requests
@@ -231,13 +231,6 @@ async function getResponse(event, client, requestId) {
231231
return passthrough()
232232
}
233233

234-
// Create a communication channel scoped to the current request.
235-
// This way events can be exchanged outside of the worker's global
236-
// "message" event listener (i.e. abstracted into functions).
237-
const operationChannel = new BroadcastChannel(
238-
`msw-response-stream-${requestId}`,
239-
)
240-
241234
// Notify the client that a request has been intercepted.
242235
const clientMessage = await sendToClient(client, {
243236
type: 'REQUEST',
@@ -262,43 +255,21 @@ async function getResponse(event, client, requestId) {
262255

263256
switch (clientMessage.type) {
264257
case 'MOCK_RESPONSE': {
265-
return respondWithMock(clientMessage.payload)
266-
}
267-
268-
case 'MOCK_RESPONSE_START': {
269-
return respondWithMockStream(operationChannel, clientMessage.payload)
258+
return respondWithMock(clientMessage.data)
270259
}
271260

272261
case 'MOCK_NOT_FOUND': {
273262
return passthrough()
274263
}
275264

276265
case 'NETWORK_ERROR': {
277-
const { name, message } = clientMessage.payload
266+
const { name, message } = clientMessage.data
278267
const networkError = new Error(message)
279268
networkError.name = name
280269

281270
// Rejecting a "respondWith" promise emulates a network error.
282271
throw networkError
283272
}
284-
285-
case 'INTERNAL_ERROR': {
286-
const parsedBody = JSON.parse(clientMessage.payload.body)
287-
288-
console.error(
289-
`\
290-
[MSW] Uncaught exception in the request handler for "%s %s":
291-
292-
${parsedBody.location}
293-
294-
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\
295-
`,
296-
request.method,
297-
request.url,
298-
)
299-
300-
return respondWithMock(clientMessage.payload)
301-
}
302273
}
303274

304275
return passthrough()
@@ -316,7 +287,7 @@ function sendToClient(client, message) {
316287
resolve(event.data)
317288
}
318289

319-
client.postMessage(JSON.stringify(message), [channel.port2])
290+
client.postMessage(message, [channel.port2])
320291
})
321292
}
322293

@@ -330,38 +301,3 @@ async function respondWithMock(response) {
330301
await sleep(response.delay)
331302
return new Response(response.body, response)
332303
}
333-
334-
function respondWithMockStream(operationChannel, mockResponse) {
335-
let streamCtrl
336-
const stream = new ReadableStream({
337-
start: (controller) => (streamCtrl = controller),
338-
})
339-
340-
return new Promise(async (resolve, reject) => {
341-
operationChannel.onmessageerror = (event) => {
342-
operationChannel.close()
343-
return reject(event.data.error)
344-
}
345-
346-
operationChannel.onmessage = (event) => {
347-
if (!event.data) {
348-
return
349-
}
350-
351-
switch (event.data.type) {
352-
case 'MOCK_RESPONSE_CHUNK': {
353-
streamCtrl.enqueue(event.data.payload)
354-
break
355-
}
356-
357-
case 'MOCK_RESPONSE_END': {
358-
streamCtrl.close()
359-
operationChannel.close()
360-
}
361-
}
362-
}
363-
364-
await sleep(mockResponse.delay)
365-
return resolve(new Response(stream, mockResponse))
366-
})
367-
}

apps/codeimage/src/components/KeyboardShortcuts/KeyboardShortcuts.css.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ export const key = style([
4949
selectors: {
5050
...withThemeMode({
5151
light: {
52-
[backgroundColorVar]: '#f3f3f3',
52+
vars: {
53+
[backgroundColorVar]: '#f3f3f3',
54+
},
5355
},
5456
dark: {
55-
[backgroundColorVar]: '#555555',
57+
vars: {
58+
[backgroundColorVar]: '#555555',
59+
},
5660
},
5761
}),
5862
},

pnpm-lock.yaml

Lines changed: 4 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)