Skip to content

Commit da0f089

Browse files
committed
chore: address review comments
1 parent 0ecfb4b commit da0f089

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

eslint.config.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import js from '@eslint/js';
22
import { defineConfig } from 'eslint/config';
3+
import { dirname } from 'node:path';
4+
import { fileURLToPath } from 'node:url';
35
import prettier from 'eslint-config-prettier';
46
import jest from 'eslint-plugin-jest';
57
import react from 'eslint-plugin-react';
68
import reactHooks from 'eslint-plugin-react-hooks';
79
import globals from 'globals';
810
import tseslint from 'typescript-eslint';
911

12+
const tsconfigRootDir = dirname(fileURLToPath(import.meta.url));
13+
1014
export default defineConfig([
1115
{
1216
plugins: {
@@ -15,7 +19,7 @@ export default defineConfig([
1519
},
1620
{
1721
linterOptions: {
18-
reportUnusedDisableDirectives: 'off',
22+
reportUnusedDisableDirectives: 'warn',
1923
},
2024
},
2125
{
@@ -26,10 +30,10 @@ export default defineConfig([
2630
'lib/',
2731
'dist/',
2832
'docs-dist/',
33+
'.docs-dist/',
2934
'.dumi/',
3035
'.doc/',
3136
'.vercel/',
32-
'src/index.d.ts',
3337
],
3438
},
3539
{
@@ -88,7 +92,7 @@ export default defineConfig([
8892
languageOptions: {
8993
parserOptions: {
9094
projectService: true,
91-
tsconfigRootDir: import.meta.dirname,
95+
tsconfigRootDir,
9296
},
9397
},
9498
},

src/hooks/useDomMotionEvents.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ import { animationEndName, transitionEndName } from '../util/motion';
66

77
export default (
88
onInternalMotionEnd: (event: MotionEvent) => void,
9-
): [(element: HTMLElement) => void, (element: HTMLElement) => void] => {
10-
const cacheElementRef = useRef<HTMLElement | undefined>(undefined);
9+
): [
10+
(element: HTMLElement | null) => void,
11+
(element: HTMLElement | null) => void,
12+
] => {
13+
const cacheElementRef = useRef<HTMLElement | null>(null);
1114

1215
// Remove events
13-
function removeMotionEvents(element: HTMLElement) {
16+
function removeMotionEvents(element: HTMLElement | null) {
1417
if (element) {
1518
element.removeEventListener(transitionEndName, onInternalMotionEnd);
1619
element.removeEventListener(animationEndName, onInternalMotionEnd);
1720
}
1821
}
1922

2023
// Patch events
21-
function patchMotionEvents(element: HTMLElement) {
24+
function patchMotionEvents(element: HTMLElement | null) {
2225
if (cacheElementRef.current && cacheElementRef.current !== element) {
2326
removeMotionEvents(cacheElementRef.current);
2427
}

tests/CSSMotion.spec.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,13 @@ describe('CSSMotion', () => {
855855
});
856856

857857
describe('strict mode', () => {
858+
let hasFindDOMNode = false;
859+
let originalFindDOMNode: unknown;
860+
858861
beforeEach(() => {
862+
hasFindDOMNode = 'findDOMNode' in ReactDOM;
863+
originalFindDOMNode = (ReactDOM as any).findDOMNode;
864+
859865
if (!('findDOMNode' in ReactDOM)) {
860866
Object.defineProperty(ReactDOM, 'findDOMNode', {
861867
value: jest.fn(),
@@ -867,7 +873,17 @@ describe('CSSMotion', () => {
867873
});
868874

869875
afterEach(() => {
870-
jest.resetAllMocks();
876+
jest.restoreAllMocks();
877+
878+
if (hasFindDOMNode) {
879+
Object.defineProperty(ReactDOM, 'findDOMNode', {
880+
value: originalFindDOMNode,
881+
writable: true,
882+
configurable: true,
883+
});
884+
} else {
885+
delete (ReactDOM as any).findDOMNode;
886+
}
871887
});
872888

873889
it('not crash when no refs are passed', () => {

0 commit comments

Comments
 (0)