Skip to content

Commit 365f6aa

Browse files
Upgrade Chakra UI/React (#1114)
Some changes due to React 18 useEffect development-time behaviour. Some e2e timing bugs caught. This should have no user-relevant changes so no rush to release it. We'll let it sit on beta for a while and may combine with a switch to Vite before release.
1 parent 187368b commit 365f6aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5869
-3156
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- run: npm ci
3737
env:
3838
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
- run: npm install --no-save @microbit-foundation/[email protected].23 @microbit-foundation/[email protected] @microbit-foundation/[email protected] @microbit-foundation/circleci-npm-package-versioner@1
39+
- run: npm install --no-save @microbit-foundation/[email protected].31 @microbit-foundation/[email protected] @microbit-foundation/[email protected] @microbit-foundation/circleci-npm-package-versioner@1
4040
if: github.repository_owner == 'microbit-foundation'
4141
env:
4242
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package-lock.json

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

package.json

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,67 @@
55
"license": "MIT",
66
"private": true,
77
"dependencies": {
8-
"@chakra-ui/icons": "^1.1.5",
9-
"@chakra-ui/react": "^1.8.7",
8+
"@chakra-ui/icons": "^2.1.1",
9+
"@chakra-ui/react": "^2.5.1",
1010
"@codemirror/autocomplete": "^6.3.0",
1111
"@codemirror/commands": "6.1.1",
1212
"@codemirror/lang-python": "^6.0.2",
1313
"@codemirror/language": "^6.2.1",
1414
"@codemirror/state": "^6.1.2",
1515
"@codemirror/view": "^6.3.0",
16-
"@emotion/react": "^11.7.1",
17-
"@emotion/styled": "^11.6.0",
16+
"@emotion/react": "^11.10.6",
17+
"@emotion/styled": "^11.10.6",
1818
"@microbit/lunr-languages": "^1.9.0-microbit.1",
1919
"@microbit/microbit-fs": "^0.9.2",
20-
"@react-three/fiber": "^7.0.27",
2120
"@sanity/block-content-to-react": "^3.0.0",
2221
"@sanity/image-url": "^1.0.1",
2322
"@testing-library/jest-dom": "^5.14.1",
24-
"@testing-library/react": "^11.2.6",
25-
"@testing-library/user-event": "^12.8.3",
23+
"@testing-library/react": "^14.0.0",
24+
"@testing-library/user-event": "^14.4.3",
2625
"@types/dompurify": "^2.3.1",
2726
"@types/lodash.debounce": "^4.0.6",
2827
"@types/lodash.sortby": "^4.7.6",
2928
"@types/lunr": "^2.3.4",
3029
"@types/marked": "^4.0.1",
3130
"@types/node": "^14.17.15",
32-
"@types/react": "^17.0.20",
33-
"@types/react-dom": "^17.0.9",
31+
"@types/react": "^18.0.0",
32+
"@types/react-dom": "^18.0.0",
3433
"base64-js": "^1.5.1",
3534
"crelt": "^1.0.5",
3635
"dapjs": "2.2.0",
3736
"dompurify": "^2.3.3",
3837
"file-saver": "^2.0.5",
39-
"framer-motion": "^5.6.0",
38+
"framer-motion": "^10.2.4",
4039
"lodash.debounce": "^4.0.8",
4140
"lodash.sortby": "^4.7.0",
4241
"lunr": "^2.3.9",
4342
"lzma": "^2.3.2",
4443
"marked": "^4.0.15",
4544
"mobile-drag-drop": "^2.3.0-rc.2",
46-
"react": "^17.0.2",
47-
"react-dom": "^17.0.2",
45+
"react": "^18.0.0",
46+
"react-dom": "^18.0.0",
4847
"react-icons": "^4.8.0",
49-
"react-intl": "^5.20.10",
48+
"react-intl": "^6.2.10",
5049
"vscode-jsonrpc": "^8.0.0",
5150
"vscode-languageserver-protocol": "^3.16.0",
5251
"web-vitals": "^1.1.1",
5352
"xterm": "4.14.1",
5453
"xterm-addon-fit": "^0.5.0"
5554
},
5655
"devDependencies": {
56+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
57+
"@chakra-ui/cli": "^2.4.1",
5758
"@craco/craco": "^7.0.0",
5859
"@formatjs/cli": "^4.2.33",
5960
"@testing-library/jest-dom": "^5.14.1",
60-
"@testing-library/react": "^11.2.6",
61-
"@testing-library/user-event": "^12.8.3",
61+
"@testing-library/react": "^14.0.0",
62+
"@testing-library/user-event": "^14.0.0",
6263
"@types/file-saver": "^2.0.3",
6364
"@types/jest": "^26.0.24",
6465
"cross-env": "^7.0.3",
6566
"pptr-testing-library": "^0.7.0",
6667
"prettier": "2.3.2",
67-
"puppeteer": "^13.4.0",
68+
"puppeteer": "13.4.0",
6869
"react-scripts": "5.0.0",
6970
"source-map-explorer": "^2.5.3",
7071
"typescript": "^4.4.2"
@@ -77,6 +78,7 @@
7778
"bundle-size-explorer": "source-map-explorer 'build/static/js/*.js'",
7879
"bundle-size-report": "source-map-explorer 'build/static/js/*.js' --html reports/bundle-size.html",
7980
"ci": "npm run typecheck && npm run test && npm run build && npm run bundle-size-report",
81+
"postinstall": "npm run theme",
8082
"start": "craco start",
8183
"build": "craco build",
8284
"test": "craco test --testPathIgnorePatterns=e2e",
@@ -86,6 +88,8 @@
8688
"test:all": "craco test --testTimeout 15000",
8789
"test:e2e": "cross-env E2E_HEADLESS=0 craco test --testPathPattern e2e -w 1 --testTimeout 15000",
8890
"test:e2e:headless": "cross-env E2E_HEADLESS=1 craco test --testPathPattern e2e -w 1 --testTimeout 15000",
91+
"theme": "chakra-cli tokens src/deployment/default/theme.ts",
92+
"theme:watch": "chakra-cli tokens src/deployment/default/theme.ts --watch",
8993
"ci:update-version": "update-ci-version",
9094
"deploy": "website-deploy-aws",
9195
"invalidate": "aws cloudfront create-invalidation --distribution-id $(printenv ${STAGE}_CLOUDFRONT_DISTRIBUTION_ID) --paths \"/*\"",

src/common/GenericDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ModalOverlay,
1313
} from "@chakra-ui/modal";
1414
import { Button, HStack, Link, Text } from "@chakra-ui/react";
15-
import { ThemeTypings } from "@chakra-ui/styled-system";
15+
import { ThemingProps } from "@chakra-ui/styled-system";
1616
import { ReactNode } from "react";
1717
import { FormattedMessage } from "react-intl";
1818
import ModalCloseButton from "./ModalCloseButton";
@@ -21,7 +21,7 @@ export interface GenericDialogProps {
2121
header?: ReactNode;
2222
body: ReactNode;
2323
footer: ReactNode;
24-
size?: ThemeTypings["components"]["Modal"]["sizes"];
24+
size?: ThemingProps<"Button">["size"];
2525
onClose: () => void;
2626
returnFocusOnClose?: boolean;
2727
finalFocusRef?: React.RefObject<HTMLButtonElement>;

src/common/InputDialog.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66
import { Button } from "@chakra-ui/button";
7-
import { Box, VStack, Text } from "@chakra-ui/layout";
7+
import { Box, Text, VStack } from "@chakra-ui/layout";
88
import {
99
Modal,
1010
ModalBody,
@@ -14,7 +14,7 @@ import {
1414
ModalOverlay,
1515
} from "@chakra-ui/modal";
1616
import { ThemeTypings } from "@chakra-ui/styled-system";
17-
import { ReactNode, useCallback, useRef, useState } from "react";
17+
import { ReactNode, useCallback, useState } from "react";
1818
import { FormattedMessage } from "react-intl";
1919

2020
export interface InputValidationResult {
@@ -39,7 +39,6 @@ export interface InputDialogProps<T> {
3939
actionLabel: string;
4040
size?: ThemeTypings["components"]["Modal"]["sizes"];
4141
validate?: (input: T) => InputValidationResult;
42-
customFocus?: boolean;
4342
finalFocusRef?: React.RefObject<HTMLButtonElement>;
4443
callback: (value: ValueOrCancelled<T>) => void;
4544
}
@@ -55,15 +54,13 @@ export const InputDialog = <T,>({
5554
actionLabel,
5655
initialValue,
5756
size,
58-
customFocus,
5957
finalFocusRef = undefined,
6058
validate = noValidation,
6159
callback,
6260
}: InputDialogProps<T>) => {
6361
const [value, setValue] = useState(initialValue);
6462
const [validationResult, setValidationResult] =
6563
useState<InputValidationResult>(validate(initialValue));
66-
const leastDestructiveRef = useRef<HTMLButtonElement>(null);
6764
const onCancel = useCallback(() => callback(undefined), [callback]);
6865
const handleSubmit = (e: React.FormEvent) => {
6966
e.preventDefault();
@@ -73,13 +70,7 @@ export const InputDialog = <T,>({
7370
};
7471

7572
return (
76-
<Modal
77-
isOpen
78-
onClose={onCancel}
79-
size={size}
80-
initialFocusRef={customFocus ? undefined : leastDestructiveRef}
81-
finalFocusRef={finalFocusRef}
82-
>
73+
<Modal isOpen onClose={onCancel} size={size} finalFocusRef={finalFocusRef}>
8374
<ModalOverlay>
8475
<ModalContent>
8576
<ModalHeader>
@@ -101,7 +92,7 @@ export const InputDialog = <T,>({
10192
</VStack>
10293
</ModalBody>
10394
<ModalFooter>
104-
<Button ref={leastDestructiveRef} onClick={onCancel}>
95+
<Button onClick={onCancel}>
10596
<FormattedMessage id="cancel-action" />
10697
</Button>
10798
<Button

src/common/use-is-unmounted.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useCallback, useEffect, useRef } from "react";
1414
const useIsUnmounted = () => {
1515
const ref = useRef(false);
1616
useEffect(() => {
17+
ref.current = false;
1718
return () => {
1819
ref.current = true;
1920
};

src/common/use-local-storage.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: MIT
55
*/
66
import { fireEvent, render, screen } from "@testing-library/react";
7-
import React from "react";
87
import { useStorage } from "./use-storage";
98

109
interface TestState {

src/common/use-raf-state.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* SPDX-License-Identifier: MIT
55
*/
6-
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
6+
import { fireEvent, render, screen } from "@testing-library/react";
77
import useRafState from "./use-raf-state";
88

99
const Test = () => {
@@ -24,6 +24,6 @@ describe("useRafState", () => {
2424

2525
fireEvent.click(screen.getByText("increment"));
2626

27-
await waitFor(() => screen.getByText("1"));
27+
await screen.findByText("1");
2828
});
2929
});

src/deployment/default/components/alert.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
*
44
* SPDX-License-Identifier: MIT
55
*/
6-
import { theme } from "@chakra-ui/react";
6+
import { StyleFunctionProps, theme } from "@chakra-ui/react";
77

88
const Alert = {
99
variants: {
10-
toast: (props: any) => {
10+
toast: (props: StyleFunctionProps) => {
1111
const base = {
12-
...theme.components.Alert.variants["solid"](props),
12+
...theme.components.Alert.variants!["solid"](props),
1313
};
1414
return base;
1515
},

src/deployment/default/components/button.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
*
44
* SPDX-License-Identifier: MIT
55
*/
6-
import { theme } from "@chakra-ui/react";
6+
import { StyleFunctionProps, theme } from "@chakra-ui/react";
77

88
const Button = {
99
variants: {
1010
// Ideally we'd drop this variant.
11-
zoom: (props: any) => {
12-
// Theme typing issue.
13-
const base: any = theme.components.Button.variants.solid(props);
11+
zoom: (props: StyleFunctionProps) => {
12+
const base = theme.components.Button.variants!.solid(props);
1413
return {
1514
...base,
1615
_hover: {
@@ -23,10 +22,9 @@ const Button = {
2322
},
2423
};
2524
},
26-
sidebar: (props: any) => {
27-
// Theme typing issue.
28-
const base: any = {
29-
...theme.components.Button.variants.ghost(props),
25+
sidebar: (props: StyleFunctionProps) => {
26+
const base = {
27+
...theme.components.Button.variants!.ghost(props),
3028
};
3129
return {
3230
...base,

src/deployment/default/components/tabs.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
*
44
* SPDX-License-Identifier: MIT
55
*/
6-
import { theme } from "@chakra-ui/react";
6+
import { StyleFunctionProps, theme } from "@chakra-ui/react";
77

88
const Tabs = {
99
variants: {
10-
sidebar: (props: any) => {
11-
// Theme typing issue.
12-
const base = (theme.components.Tabs.variants["solid-rounded"] as any)(
13-
props
14-
);
10+
sidebar: (props: StyleFunctionProps) => {
11+
const base = theme.components.Tabs.variants!["solid-rounded"](props);
1512
return {
1613
...base,
1714
tablist: {

src/documentation/common/DocString.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe("DocString", () => {
1010
it("works", () => {
1111
const markdown =
1212
"```python\ntestLib.Validator.read_write_prop (property)\n```\n---\nThe read-write property.";
13-
const rendered = render(<DocString value={markdown} />);
14-
expect(rendered.baseElement.innerHTML).toMatchInlineSnapshot(`
13+
const view = render(<DocString value={markdown} />);
14+
expect(view.baseElement.innerHTML).toMatchInlineSnapshot(`
1515
"<div><div class=\\"docs-spacing docs-code css-0\\"><pre><code class=\\"language-python\\">testLib.Validator.read_write_prop (property)
1616
</code></pre>
1717
<hr>

src/documentation/common/DocumentationContent.test.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import DocumentationContent from "./DocumentationContent";
1212

1313
jest.mock("@chakra-ui/image", () => ({
1414
Image: ({ src, w, h }: ImageProps) => (
15+
// eslint-disable-next-line jsx-a11y/alt-text
1516
<img src={src} width={w as string} height={h as string} />
1617
),
1718
}));
@@ -46,9 +47,9 @@ describe("DocumentationContent", () => {
4647
style: "normal",
4748
},
4849
];
49-
const rendered = render(<DocumentationContent content={content} />);
50-
expect(rendered.container.innerHTML).toMatchInlineSnapshot(
51-
`"<div class=\\"chakra-stack css-bs1yt6\\"><p><a target=\\"_blank\\" rel=\\"nofollow noopener\\" class=\\"chakra-link css-1w3ukj\\" href=\\"https://www.bbc.co.uk/bitesize/guides/zscvxfr/revision/4\\">Read more about ASCII<svg stroke=\\"currentColor\\" fill=\\"currentColor\\" stroke-width=\\"0\\" viewBox=\\"0 0 24 24\\" focusable=\\"false\\" class=\\"chakra-icon css-q1kx43\\" height=\\"1em\\" width=\\"1em\\" xmlns=\\"http://www.w3.org/2000/svg\\"><path d=\\"M10 6V8H5V19H16V14H18V20C18 20.5523 17.5523 21 17 21H4C3.44772 21 3 20.5523 3 20V7C3 6.44772 3.44772 6 4 6H10ZM21 3V11H19L18.9999 6.413L11.2071 14.2071L9.79289 12.7929L17.5849 5H13V3H21Z\\"></path></svg></a>.</p></div>"`
50+
const view = render(<DocumentationContent content={content} />);
51+
expect(view.container.innerHTML).toMatchInlineSnapshot(
52+
`"<div class=\\"chakra-stack css-iewcov\\"><p><a target=\\"_blank\\" rel=\\"nofollow noopener\\" class=\\"chakra-link css-1w3ukj\\" href=\\"https://www.bbc.co.uk/bitesize/guides/zscvxfr/revision/4\\">Read more about ASCII<svg stroke=\\"currentColor\\" fill=\\"currentColor\\" stroke-width=\\"0\\" viewBox=\\"0 0 24 24\\" focusable=\\"false\\" class=\\"chakra-icon css-q1kx43\\" height=\\"1em\\" width=\\"1em\\" xmlns=\\"http://www.w3.org/2000/svg\\"><path d=\\"M10 6V8H5V19H16V14H18V20C18 20.5523 17.5523 21 17 21H4C3.44772 21 3 20.5523 3 20V7C3 6.44772 3.44772 6 4 6H10ZM21 3V11H19L18.9999 6.413L11.2071 14.2071L9.79289 12.7929L17.5849 5H13V3H21Z\\"></path></svg></a>.</p></div>"`
5253
);
5354
});
5455

@@ -63,10 +64,10 @@ describe("DocumentationContent", () => {
6364
},
6465
},
6566
];
66-
const rendered = render(<DocumentationContent content={content} />);
67+
const view = render(<DocumentationContent content={content} />);
6768
// This relies on the mock above because Chakra UI's images have the src added later.
68-
expect(rendered.container.innerHTML).toMatchInlineSnapshot(
69-
`"<div class=\\"chakra-stack css-bs1yt6\\"><img src=\\"https://cdn.sanity.io/images/ajwvhvgo/apps/9fccaf51a164fedc98662188593de19bfb9be8ad-435x512.png?w=300&amp;q=80&amp;fit=max&amp;auto=format\\"></div>"`
69+
expect(view.container.innerHTML).toMatchInlineSnapshot(
70+
`"<div class=\\"chakra-stack css-iewcov\\"><img src=\\"https://cdn.sanity.io/images/ajwvhvgo/apps/9fccaf51a164fedc98662188593de19bfb9be8ad-435x512.png?w=300&amp;q=80&amp;fit=max&amp;auto=format\\"></div>"`
7071
);
7172
});
7273
});

src/documentation/common/DocumentationContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* SPDX-License-Identifier: MIT
55
*/
6-
import Icon from "@chakra-ui/icon";
6+
import { Icon } from "@chakra-ui/icon";
77
import { Image } from "@chakra-ui/image";
88
import { Box, Link, Stack, Text } from "@chakra-ui/layout";
99
import { Collapse } from "@chakra-ui/react";

0 commit comments

Comments
 (0)