Skip to content

Commit 125c515

Browse files
CompuIvesDokomecodesandbot
authored
fix: raise react peer dependency to 19 (#1245)
* fix: raise react peer dependency to 19 * fix(landing): invalid isMounted judgment (#1238) * fix all tests * fix render hook * update lockfile --------- Co-authored-by: DoKom <[email protected]> Co-authored-by: codesandbox-bot <[email protected]>
1 parent 760f83b commit 125c515

File tree

15 files changed

+2074
-1709
lines changed

15 files changed

+2074
-1709
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
"eslint-plugin-jsx-a11y": "^6.3.1",
5656
"eslint-plugin-react": "^7.20.3",
5757
"eslint-plugin-react-hooks": "^4.0.8",
58-
"jest": "^27.4.5",
58+
"jest": "^29.7.0",
59+
"jest-environment-jsdom": "^29.7.0",
5960
"lerna": "^7.4.1",
6061
"lerna-changelog": "^2.2.0",
6162
"lint-staged": "^10.5.4",
6263
"prettier": "^2.2.1",
63-
"react-test-renderer": "^18.1.0",
6464
"rollup": "^3.9.1",
6565
"rollup-plugin-string": "^3.0.0",
6666
"turbo": "^1.5.5"

sandpack-react/jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
setupFilesAfterEnv: ["<rootDir>/src/setup.jest.ts"],
3+
testEnvironment: "jsdom",
4+
testEnvironmentOptions: {
5+
customExportConditions: [""],
6+
},
7+
globals: {
8+
"process.env.TEST_ENV": "true",
9+
},
10+
};

sandpack-react/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777
"@codesandbox/sandpack-themes": "^2.0.21",
7878
"@storybook/react": "^7.5.1",
7979
"@storybook/react-vite": "^7.5.1",
80-
"@testing-library/react-hooks": "8.0.1",
80+
"@testing-library/dom": "^10.4.0",
81+
"@testing-library/jest-dom": "^6.6.3",
82+
"@testing-library/react": "^16.2.0",
8183
"@types/fs-extra": "^5.0.4",
8284
"@types/glob": "^5.0.35",
8385
"@types/lz-string": "^1.3.34",
@@ -91,7 +93,7 @@
9193
"typescript": "^5.2.2"
9294
},
9395
"peerDependencies": {
94-
"react": "^16.8.0 || ^17 || ^18",
95-
"react-dom": "^16.8.0 || ^17 || ^18"
96+
"react": "^16.8.0 || ^17 || ^18 || ^19",
97+
"react-dom": "^16.8.0 || ^17 || ^18 || ^19"
9698
}
9799
}
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* @jest-environment jsdom
33
*/
4-
import { act } from "@testing-library/react-hooks";
4+
import { act, render, screen } from "@testing-library/react";
5+
import "@testing-library/jest-dom";
56
import React from "react";
6-
import { create } from "react-test-renderer";
77

88
import { SandpackProvider } from "../../";
99

@@ -13,7 +13,7 @@ describe("read-only", () => {
1313
jest.useFakeTimers();
1414

1515
it("should render the read-only flag", () => {
16-
const { root } = create(
16+
render(
1717
<SandpackProvider>
1818
<SandpackCodeEditor readOnly />
1919
</SandpackProvider>
@@ -23,13 +23,12 @@ describe("read-only", () => {
2323
jest.runAllTimers();
2424
});
2525

26-
const readOnlyFlag = root.findByProps({ "data-testId": "read-only" });
27-
28-
expect(readOnlyFlag.props.children).toBe("Read-only");
26+
const readOnlyFlag = screen.getByTestId("read-only");
27+
expect(readOnlyFlag).toHaveTextContent("Read-only");
2928
});
3029

3130
it("should not render the read-only flag, when showReadOnly is false", () => {
32-
const { root } = create(
31+
render(
3332
<SandpackProvider>
3433
<SandpackCodeEditor showReadOnly={false} readOnly />
3534
</SandpackProvider>
@@ -39,12 +38,6 @@ describe("read-only", () => {
3938
jest.runAllTimers();
4039
});
4140

42-
try {
43-
root.findByProps({ "data-testId": "read-only" });
44-
} catch (err) {
45-
expect(err.message).toBe(
46-
'No instances found with props: {"data-testId":"read-only"}'
47-
);
48-
}
41+
expect(screen.queryByTestId("read-only")).not.toBeInTheDocument();
4942
});
5043
});

sandpack-react/src/components/CodeEditor/CodeMirror.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ export const CodeMirror = React.forwardRef<CodeMirrorRef, CodeMirrorProps>(
183183
[decorators]
184184
);
185185

186-
const useStaticReadOnly = readOnly && decorators?.length === 0;
186+
const useStaticReadOnly =
187+
readOnly && (decorators?.length === 0 || decorators === undefined);
187188

188189
React.useEffect(() => {
189190
if (!wrapper.current || !shouldInitEditor || useStaticReadOnly) {

0 commit comments

Comments
 (0)