Skip to content

Commit 8658e8d

Browse files
authored
Bump most frontend dependencies (#4678)
2 parents 23e5063 + 8c98add commit 8658e8d

File tree

7 files changed

+1055
-892
lines changed

7 files changed

+1055
-892
lines changed

frontend/.storybook/public/mockServiceWorker.js

Lines changed: 91 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
* Mock Service Worker.
66
* @see https://github.com/mswjs/msw
77
* - Please do NOT modify this file.
8-
* - Please do NOT serve this file on production.
98
*/
109

11-
const PACKAGE_VERSION = '2.8.7'
12-
const INTEGRITY_CHECKSUM = '00729d72e3b82faf54ca8b9621dbb96f'
10+
const PACKAGE_VERSION = '2.10.2'
11+
const INTEGRITY_CHECKSUM = 'f5825c521429caf22a4dd13b66e243af'
1312
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
1413
const activeClientIds = new Set()
1514

16-
self.addEventListener('install', function () {
15+
addEventListener('install', function () {
1716
self.skipWaiting()
1817
})
1918

20-
self.addEventListener('activate', function (event) {
19+
addEventListener('activate', function (event) {
2120
event.waitUntil(self.clients.claim())
2221
})
2322

24-
self.addEventListener('message', async function (event) {
25-
const clientId = event.source.id
23+
addEventListener('message', async function (event) {
24+
const clientId = Reflect.get(event.source || {}, 'id')
2625

2726
if (!clientId || !self.clients) {
2827
return
@@ -94,17 +93,18 @@ self.addEventListener('message', async function (event) {
9493
}
9594
})
9695

97-
self.addEventListener('fetch', function (event) {
98-
const { request } = event
99-
96+
addEventListener('fetch', function (event) {
10097
// Bypass navigation requests.
101-
if (request.mode === 'navigate') {
98+
if (event.request.mode === 'navigate') {
10299
return
103100
}
104101

105102
// Opening the DevTools triggers the "only-if-cached" request
106103
// that cannot be handled by the worker. Bypass such requests.
107-
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
104+
if (
105+
event.request.cache === 'only-if-cached' &&
106+
event.request.mode !== 'same-origin'
107+
) {
108108
return
109109
}
110110

@@ -115,48 +115,62 @@ self.addEventListener('fetch', function (event) {
115115
return
116116
}
117117

118-
// Generate unique request ID.
119118
const requestId = crypto.randomUUID()
120119
event.respondWith(handleRequest(event, requestId))
121120
})
122121

122+
/**
123+
* @param {FetchEvent} event
124+
* @param {string} requestId
125+
*/
123126
async function handleRequest(event, requestId) {
124127
const client = await resolveMainClient(event)
128+
const requestCloneForEvents = event.request.clone()
125129
const response = await getResponse(event, client, requestId)
126130

127131
// Send back the response clone for the "response:*" life-cycle events.
128132
// Ensure MSW is active and ready to handle the message, otherwise
129133
// this message will pend indefinitely.
130134
if (client && activeClientIds.has(client.id)) {
131-
;(async function () {
132-
const responseClone = response.clone()
133-
134-
sendToClient(
135-
client,
136-
{
137-
type: 'RESPONSE',
138-
payload: {
139-
requestId,
140-
isMockedResponse: IS_MOCKED_RESPONSE in response,
135+
const serializedRequest = await serializeRequest(requestCloneForEvents)
136+
137+
// Clone the response so both the client and the library could consume it.
138+
const responseClone = response.clone()
139+
140+
sendToClient(
141+
client,
142+
{
143+
type: 'RESPONSE',
144+
payload: {
145+
isMockedResponse: IS_MOCKED_RESPONSE in response,
146+
request: {
147+
id: requestId,
148+
...serializedRequest,
149+
},
150+
response: {
141151
type: responseClone.type,
142152
status: responseClone.status,
143153
statusText: responseClone.statusText,
144-
body: responseClone.body,
145154
headers: Object.fromEntries(responseClone.headers.entries()),
155+
body: responseClone.body,
146156
},
147157
},
148-
[responseClone.body],
149-
)
150-
})()
158+
},
159+
responseClone.body ? [serializedRequest.body, responseClone.body] : [],
160+
)
151161
}
152162

153163
return response
154164
}
155165

156-
// Resolve the main client for the given event.
157-
// Client that issues a request doesn't necessarily equal the client
158-
// that registered the worker. It's with the latter the worker should
159-
// communicate with during the response resolving phase.
166+
/**
167+
* Resolve the main client for the given event.
168+
* Client that issues a request doesn't necessarily equal the client
169+
* that registered the worker. It's with the latter the worker should
170+
* communicate with during the response resolving phase.
171+
* @param {FetchEvent} event
172+
* @returns {Promise<Client | undefined>}
173+
*/
160174
async function resolveMainClient(event) {
161175
const client = await self.clients.get(event.clientId)
162176

@@ -184,12 +198,16 @@ async function resolveMainClient(event) {
184198
})
185199
}
186200

201+
/**
202+
* @param {FetchEvent} event
203+
* @param {Client | undefined} client
204+
* @param {string} requestId
205+
* @returns {Promise<Response>}
206+
*/
187207
async function getResponse(event, client, requestId) {
188-
const { request } = event
189-
190208
// Clone the request because it might've been already used
191209
// (i.e. its body has been read and sent to the client).
192-
const requestClone = request.clone()
210+
const requestClone = event.request.clone()
193211

194212
function passthrough() {
195213
// Cast the request headers to a new Headers instance
@@ -230,29 +248,17 @@ async function getResponse(event, client, requestId) {
230248
}
231249

232250
// Notify the client that a request has been intercepted.
233-
const requestBuffer = await request.arrayBuffer()
251+
const serializedRequest = await serializeRequest(event.request)
234252
const clientMessage = await sendToClient(
235253
client,
236254
{
237255
type: 'REQUEST',
238256
payload: {
239257
id: requestId,
240-
url: request.url,
241-
mode: request.mode,
242-
method: request.method,
243-
headers: Object.fromEntries(request.headers.entries()),
244-
cache: request.cache,
245-
credentials: request.credentials,
246-
destination: request.destination,
247-
integrity: request.integrity,
248-
redirect: request.redirect,
249-
referrer: request.referrer,
250-
referrerPolicy: request.referrerPolicy,
251-
body: requestBuffer,
252-
keepalive: request.keepalive,
258+
...serializedRequest,
253259
},
254260
},
255-
[requestBuffer],
261+
[serializedRequest.body],
256262
)
257263

258264
switch (clientMessage.type) {
@@ -268,6 +274,12 @@ async function getResponse(event, client, requestId) {
268274
return passthrough()
269275
}
270276

277+
/**
278+
* @param {Client} client
279+
* @param {any} message
280+
* @param {Array<Transferable>} transferrables
281+
* @returns {Promise<any>}
282+
*/
271283
function sendToClient(client, message, transferrables = []) {
272284
return new Promise((resolve, reject) => {
273285
const channel = new MessageChannel()
@@ -280,14 +292,18 @@ function sendToClient(client, message, transferrables = []) {
280292
resolve(event.data)
281293
}
282294

283-
client.postMessage(
284-
message,
285-
[channel.port2].concat(transferrables.filter(Boolean)),
286-
)
295+
client.postMessage(message, [
296+
channel.port2,
297+
...transferrables.filter(Boolean),
298+
])
287299
})
288300
}
289301

290-
async function respondWithMock(response) {
302+
/**
303+
* @param {Response} response
304+
* @returns {Response}
305+
*/
306+
function respondWithMock(response) {
291307
// Setting response status code to 0 is a no-op.
292308
// However, when responding with a "Response.error()", the produced Response
293309
// instance will have status code set to 0. Since it's not possible to create
@@ -305,3 +321,24 @@ async function respondWithMock(response) {
305321

306322
return mockedResponse
307323
}
324+
325+
/**
326+
* @param {Request} request
327+
*/
328+
async function serializeRequest(request) {
329+
return {
330+
url: request.url,
331+
mode: request.mode,
332+
method: request.method,
333+
headers: Object.fromEntries(request.headers.entries()),
334+
cache: request.cache,
335+
credentials: request.credentials,
336+
destination: request.destination,
337+
integrity: request.integrity,
338+
redirect: request.redirect,
339+
referrer: request.referrer,
340+
referrerPolicy: request.referrerPolicy,
341+
body: await request.arrayBuffer(),
342+
keepalive: request.keepalive,
343+
}
344+
}

frontend/knip.config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@
66
import type { KnipConfig } from "knip";
77

88
export default {
9-
entry: [
10-
"src/main.tsx",
11-
"src/swagger.ts",
12-
"src/routes/*",
13-
"i18next-parser.config.ts",
14-
],
9+
entry: ["src/main.tsx", "src/swagger.ts", "src/routes/*"],
1510
ignore: ["src/gql/*", "src/routeTree.gen.ts", ".storybook/locales.ts"],
1611
ignoreDependencies: [
1712
// This is used by the tailwind PostCSS plugin, but not detected by knip
1813
"postcss-nesting",
19-
// We're using @storybook/addon-essentials to simplify upgrades, but knip doesn't detect them
20-
"@storybook/addon-*",
2114
],
2215
} satisfies KnipConfig;

0 commit comments

Comments
 (0)