Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: React 18 compatibility #1458

Closed
wants to merge 6 commits into from
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"husky": "~9.0.11",
"hygen": "~6.1.5",
"pinst": "~3.0.0",
"turbo": "~2.0.11",
"turbo": "~2.1.3",
"update-readme": "workspace:~",
"webpack": "~5.94.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/css-in-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@rollup/plugin-json": "~4.1.0",
"@rollup/plugin-node-resolve": "~13.1.3",
"@rollup/plugin-typescript": "~8.3.4",
"@types/jest": "~29.5.12",
"@types/jest": "~29.5.13",
"@types/stylis": "^4.0.2",
"bump": "workspace:~",
"eslint": "~8.38.0",
Expand All @@ -57,8 +57,8 @@
"rollup": "~2.79.2",
"rollup-plugin-terser": "~7.0.2",
"ts-jest": "~29.2.4",
"typedoc": "~0.25.13",
"typescript": "~5.5.4"
"typedoc": "~0.26.8",
"typescript": "~5.6.3"
},
"dependencies": {
"@emotion/hash": "^0.9.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/css-supports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"lint-all": "workspace:~",
"prettier": "~2.8.7",
"rimraf": "~3.0.2",
"typedoc": "~0.25.13",
"typescript": "~5.5.4"
"typedoc": "~0.26.8",
"typescript": "~5.6.3"
},
"dependencies": {
"@rocket.chat/memo": "workspace:~"
Expand Down
6 changes: 3 additions & 3 deletions packages/emitter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@rollup/plugin-json": "~4.1.0",
"@rollup/plugin-node-resolve": "~13.1.3",
"@rollup/plugin-typescript": "~8.3.4",
"@types/jest": "~29.5.12",
"@types/jest": "~29.5.13",
"bump": "workspace:~",
"eslint": "~8.38.0",
"jest": "~29.7.0",
Expand All @@ -57,7 +57,7 @@
"rollup": "~2.79.2",
"rollup-plugin-terser": "~7.0.2",
"ts-jest": "~29.2.4",
"typedoc": "~0.25.13",
"typescript": "~5.5.4"
"typedoc": "~0.26.8",
"typescript": "~5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-config-alt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"prettier": "~2.7.1"
},
"devDependencies": {
"@babel/eslint-parser": "~7.21.3",
"@babel/eslint-parser": "~7.25.8",
"bump": "workspace:~",
"eslint": "~8.38.0",
"lint-all": "workspace:~",
Expand Down
7 changes: 0 additions & 7 deletions packages/fuselage-hooks/jest.config.js

This file was deleted.

31 changes: 31 additions & 0 deletions packages/fuselage-hooks/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Config } from 'jest';

export default {
projects: [
{
displayName: 'server',
testEnvironment: 'node',
preset: 'ts-jest',
errorOnDeprecated: true,
testMatch: ['<rootDir>/src/**/*.server.spec.{ts,tsx}'],
setupFilesAfterEnv: [
'testing-utils/setup/noErrorsLogged',
'<rootDir>/src/jest-setup.ts',
],
},
{
displayName: 'client',
testEnvironment: 'jsdom',
preset: 'ts-jest',
errorOnDeprecated: true,
testMatch: [
'<rootDir>/src/**/*.spec.{ts,tsx}',
'!**/*.server.spec.{ts,tsx}',
],
setupFilesAfterEnv: [
'testing-utils/setup/noErrorsLogged',
'<rootDir>/src/jest-setup.ts',
],
},
],
} satisfies Config;
20 changes: 11 additions & 9 deletions packages/fuselage-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,33 @@
"@rollup/plugin-json": "~4.1.0",
"@rollup/plugin-node-resolve": "~13.1.3",
"@rollup/plugin-typescript": "~8.3.4",
"@testing-library/react": "~16.0.1",
"@testing-library/react-hooks": "~8.0.1",
"@testing-library/user-event": "~14.5.2",
"@types/jest": "~29.5.12",
"@types/react": "~17.0.80",
"@types/react-dom": "~17.0.25",
"@types/resize-observer-browser": "~0.1.7",
"@types/use-sync-external-store": "~0.0.3",
"@types/jest": "~29.5.13",
"@types/react": "~18.3.11",
"@types/react-dom": "~18.3.0",
"@types/resize-observer-browser": "~0.1.11",
"@types/use-sync-external-store": "~0.0.6",
"bump": "workspace:~",
"eslint": "~8.38.0",
"jest": "~29.7.0",
"lint-all": "workspace:~",
"npm-run-all": "^4.1.5",
"prettier": "~2.8.7",
"react": "^17.0.2",
"react": "~18.3.1",
"react-dom": "~18.3.1",
"rimraf": "~5.0.0",
"rollup": "~2.79.2",
"rollup-plugin-terser": "~7.0.2",
"testing-utils": "workspace:~",
"ts-jest": "~29.2.4",
"typedoc": "~0.25.13",
"typescript": "~5.5.4"
"typedoc": "~0.26.8",
"typescript": "~5.6.3"
},
"peerDependencies": {
"@rocket.chat/fuselage-tokens": "*",
"react": "^17.0.2"
"react": "*"
},
"dependencies": {
"use-sync-external-store": "~1.2.0"
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage-hooks/src/helpers/emptyDeps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const emptyDeps: ReadonlyArray<unknown> = [];
3 changes: 3 additions & 0 deletions packages/fuselage-hooks/src/jest-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { configure } from '@testing-library/react';

configure({ reactStrictMode: true });
10 changes: 5 additions & 5 deletions packages/fuselage-hooks/src/useAutoFocus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { useImperativeHandle, useState } from 'react';

import { useAutoFocus } from './useAutoFocus';
Expand All @@ -17,7 +17,7 @@ it('invokes focus', async () => {

act(() => undefined);

expect(focus).toHaveBeenCalledTimes(1);
expect(focus).toHaveBeenCalled();
});

it('does not invoke focus if isFocused is false', () => {
Expand All @@ -28,7 +28,7 @@ it('does not invoke focus if isFocused is false', () => {

act(() => undefined);

expect(focus).toHaveBeenCalledTimes(0);
expect(focus).not.toHaveBeenCalled();
});

it('invokes focus if isFocused is toggled', () => {
Expand All @@ -41,11 +41,11 @@ it('invokes focus if isFocused is toggled', () => {

act(() => undefined);

expect(focus).toHaveBeenCalledTimes(0);
expect(focus).not.toHaveBeenCalled();

act(() => {
result.current.setIsFocused(true);
});

expect(focus).toHaveBeenCalledTimes(1);
expect(focus).toHaveBeenCalled();
});
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useBorderBoxSize.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';
import { useRef } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useBorderBoxSize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import type { RefObject } from 'react';
import { useRef } from 'react';
import { withResizeObserverMock } from 'testing-utils/mocks/withResizeObserverMock';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useBreakpoints.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import breakpoints from '@rocket.chat/fuselage-tokens/breakpoints.json';
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { withMatchMediaMock } from 'testing-utils/mocks/withMatchMediaMock';

import { useBreakpoints } from './useBreakpoints';
Expand Down
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useClipboard.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useClipboard } from './useClipboard';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useClipboard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { withClipboardMock } from 'testing-utils/mocks/withClipboardMock';

import { useClipboard } from './useClipboard';
Expand Down
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useContentBoxSize.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';
import { useRef } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useContentBoxSize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import type { RefObject } from 'react';
import { useRef } from 'react';
import { withResizeObserverMock } from 'testing-utils/mocks/withResizeObserverMock';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useDebouncedCallback } from './useDebouncedCallback';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useDebouncedCallback.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { useState } from 'react';

import { useDebouncedCallback } from './useDebouncedCallback';
Expand Down
4 changes: 3 additions & 1 deletion packages/fuselage-hooks/src/useDebouncedCallback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { DependencyList } from 'react';
import { useMemo, useCallback, useRef, useEffect } from 'react';

import { emptyDeps } from './helpers/emptyDeps';

/**
* Hook to memoize a debounced version of a callback.
*
Expand All @@ -13,7 +15,7 @@ import { useMemo, useCallback, useRef, useEffect } from 'react';
export const useDebouncedCallback = <P extends unknown[]>(
callback: (...args: P) => unknown,
delay: number,
deps?: DependencyList
deps: DependencyList = emptyDeps
): ((...args: P) => unknown) & {
flush: () => void;
cancel: () => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useDebouncedReducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';

import { useDebouncedReducer } from './useDebouncedReducer';

Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useDebouncedState.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';

import { useDebouncedState } from './useDebouncedState';

Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useDebouncedUpdates.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { useState } from 'react';

import { useDebouncedUpdates } from './useDebouncedUpdates';
Expand Down
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useDebouncedValue.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useDebouncedValue } from './useDebouncedValue';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useDebouncedValue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { useReducer } from 'react';

import { useDebouncedValue } from './useDebouncedValue';
Expand Down
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useEffectEvent.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useEffectEvent } from './useEffectEvent';
Expand Down
7 changes: 5 additions & 2 deletions packages/fuselage-hooks/src/useEffectEvent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, renderHook } from '@testing-library/react-hooks';
import { act, renderHook } from '@testing-library/react';
import { useState } from 'react';

import { useEffectEvent } from './useEffectEvent';
Expand All @@ -8,9 +8,12 @@ it('returns a stable callback', () => {

const { result, rerender } = renderHook(() => useEffectEvent(fn));

const stableCallbackA = result.current;

rerender();

const [stableCallbackA, stableCallbackB] = result.all;
const stableCallbackB = result.current;

expect(stableCallbackB).toBe(stableCallbackA);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
Expand Down
4 changes: 2 additions & 2 deletions packages/fuselage-hooks/src/useIsomorphicLayoutEffect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';

import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';

Expand All @@ -11,5 +11,5 @@ it('performs a useLayoutEffect', () => {
});
});

expect(watcher).toBeCalledTimes(1);
expect(watcher).toHaveBeenCalled();
});
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useLazyRef.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useLazyRef } from './useLazyRef';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useLazyRef.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';

import { useLazyRef } from './useLazyRef';

Expand Down
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useLocalStorage.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useLocalStorage } from './useStorage';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useLocalStorage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';

import { useLocalStorage } from './useStorage';

Expand Down
4 changes: 0 additions & 4 deletions packages/fuselage-hooks/src/useMediaQueries.server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

import { renderHook } from '@testing-library/react-hooks/server';

import { useMediaQueries } from './useMediaQueries';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/src/useMediaQueries.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { withMatchMediaMock } from 'testing-utils/mocks/withMatchMediaMock';

import { useMediaQueries } from './useMediaQueries';
Expand Down
Loading
Loading