Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions .storybook/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* - Please do NOT modify this file.
*/

const PACKAGE_VERSION = '2.10.2'
const INTEGRITY_CHECKSUM = 'f5825c521429caf22a4dd13b66e243af'
const PACKAGE_VERSION = '2.12.4'
const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()

Expand Down Expand Up @@ -71,11 +71,6 @@ addEventListener('message', async function (event) {
break
}

case 'MOCK_DEACTIVATE': {
activeClientIds.delete(clientId)
break
}

case 'CLIENT_CLOSED': {
activeClientIds.delete(clientId)

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

addEventListener('fetch', function (event) {
const requestInterceptedAt = Date.now()

// Bypass navigation requests.
if (event.request.mode === 'navigate') {
return
Expand All @@ -110,23 +107,29 @@ addEventListener('fetch', function (event) {

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

const requestId = crypto.randomUUID()
event.respondWith(handleRequest(event, requestId))
event.respondWith(handleRequest(event, requestId, requestInterceptedAt))
})

/**
* @param {FetchEvent} event
* @param {string} requestId
* @param {number} requestInterceptedAt
*/
async function handleRequest(event, requestId) {
async function handleRequest(event, requestId, requestInterceptedAt) {
const client = await resolveMainClient(event)
const requestCloneForEvents = event.request.clone()
const response = await getResponse(event, client, requestId)
const response = await getResponse(
event,
client,
requestId,
requestInterceptedAt,
)

// Send back the response clone for the "response:*" life-cycle events.
// Ensure MSW is active and ready to handle the message, otherwise
Expand Down Expand Up @@ -202,9 +205,10 @@ async function resolveMainClient(event) {
* @param {FetchEvent} event
* @param {Client | undefined} client
* @param {string} requestId
* @param {number} requestInterceptedAt
* @returns {Promise<Response>}
*/
async function getResponse(event, client, requestId) {
async function getResponse(event, client, requestId, requestInterceptedAt) {
// Clone the request because it might've been already used
// (i.e. its body has been read and sent to the client).
const requestClone = event.request.clone()
Expand Down Expand Up @@ -255,6 +259,7 @@ async function getResponse(event, client, requestId) {
type: 'REQUEST',
payload: {
id: requestId,
interceptedAt: requestInterceptedAt,
...serializedRequest,
},
},
Expand Down
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ module.exports = {
messagesDir: './i18n/json',
},
],
[
'babel-plugin-transform-define',
{
__VERSION__: require('./package.json').version,
},
],
],
env: {
development: {
Expand Down
26 changes: 17 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"yarn": ">=1.10.0"
},
"scripts": {
"prepare": "yarn build:prod:es",
"build": "yarn build:dev:dist",
"build:ci:dist": "LANGUAGE=en-US ENTRY=explorer REACT=true yarn build:prod:dist",
"build:ci:es": "yarn build:prod:es",
Expand All @@ -73,7 +74,7 @@
"lint:js": "eslint --max-warnings=0 .",
"lint:ts": "tsc",
"lint:css": "stylelint \"src/**/*.scss\"",
"prebuild:es": "npm-run-all copy:styles ts:defs copy:flow",
"prebuild:es": "npm-run-all copy:styles copy:flow",
"release": "yarn release:beta",
"release:beta": "DIST=beta BRANCH=master scripts/release.sh",
"release:hotfix": "DIST=latest HOTFIX=true scripts/release.sh",
Expand All @@ -98,7 +99,11 @@
"last 2 Edge versions",
"last 2 iOS versions"
],
"development": ["last 1 Chrome versions", "last 1 Firefox versions", "last 1 Safari versions"]
"development": [
"last 1 Chrome versions",
"last 1 Firefox versions",
"last 1 Safari versions"
]
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -190,6 +195,7 @@
"babel-plugin-react-remove-properties": "^0.3.0",
"babel-plugin-rewire": "^1.0.0",
"babel-plugin-styled-components": "^1.10.7",
"babel-plugin-transform-define": "^2.1.4",
"babel-preset-react-app": "^9.1.0",
"chromatic": "^11.26.1",
"circular-dependency-plugin": "^5.2.2",
Expand Down Expand Up @@ -249,13 +255,13 @@
"prop-types": "^15.7.2",
"properties-parser": "^0.3.1",
"query-string": "5.1.1",
"react": "^18.3.1",
"react": "^19.0.0",
"react-animate-height": "^3.2.3",
"react-aria-components": "^1.10.1",
"react-beautiful-dnd": "^13.1.1",
"react-docgen-typescript": "^1.16.1",
"react-docgen-typescript-loader": "^3.6.0",
"react-dom": "^18.3.1",
"react-dom": "^19.0.0",
"react-draggable": "^4.5.0",
"react-immutable-proptypes": "^2.1.0",
"react-intl": "^6.6.8",
Expand Down Expand Up @@ -285,7 +291,7 @@
"stylelint-config-standard": "^38.0.0",
"stylelint-config-standard-scss": "^14.0.0",
"stylelint-order": "^6.0.4",
"tabbable": "^1.1.3",
"tabbable": "^6.2.0",
"ts-loader": "^6.2.1",
"typescript": "5.2.2",
"uuid": "^8.3.2",
Expand Down Expand Up @@ -332,11 +338,11 @@
"mousetrap": "^1.6.3",
"pikaday": "^1.8.0",
"query-string": "5.1.1",
"react": "^17.0.1 || ^18.0.0",
"react": "^17.0.1 || ^18.0.0 || ^19.0.0",
"react-animate-height": "^3.2.3",
"react-aria-components": "^1.10.1",
"react-beautiful-dnd": "^13.1.1",
"react-dom": "^17.0.1 || ^18.0.0",
"react-dom": "^17.0.1 || ^18.0.0 || ^19.0.0",
"react-draggable": "^4.5.0",
"react-immutable-proptypes": "^2.1.0",
"react-intl": ">=2.9.0",
Expand All @@ -354,7 +360,7 @@
"sanitize-html": "^2.14.0",
"sass": "1.45.0",
"scroll-into-view-if-needed": "^2.2.20",
"tabbable": "^1.1.2",
"tabbable": "^6.2.0",
"uuid": "^8.3.2"
},
"comments": {
Expand All @@ -363,6 +369,8 @@
}
},
"msw": {
"workerDirectory": [".storybook/public"]
"workerDirectory": [
".storybook/public"
]
}
}
Loading
Loading