Skip to content

Commit 8b7599b

Browse files
committed
fix: test issues
1 parent f76b493 commit 8b7599b

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

src/Frame.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ function Frame({
5858
const [iframeLoaded, setIframeLoaded] = useState(false);
5959
const internalRef = useRef<HTMLIFrameElement | null>(null);
6060
const nodeRef = externalRef || internalRef;
61-
const isMounted = useRef(false);
6261
const loadCheckInterval = useRef<ReturnType<typeof setInterval> | null>(null);
6362

6463
const getDoc = useCallback((): Document | null => {
@@ -85,8 +84,6 @@ function Frame({
8584
}, [iframeLoaded]);
8685

8786
useEffect(() => {
88-
isMounted.current = true;
89-
9087
const doc = getDoc();
9188
const frame = nodeRef.current;
9289
const interval = loadCheckInterval.current;
@@ -96,8 +93,6 @@ function Frame({
9693
}
9794

9895
return () => {
99-
isMounted.current = false;
100-
10196
if (frame?.contentWindow) {
10297
frame.contentWindow.removeEventListener('DOMContentLoaded', handleLoad);
10398
}
@@ -106,15 +101,11 @@ function Frame({
106101
clearInterval(interval);
107102
}
108103
};
109-
// nodeRef is stable (either internalRef from useRef or external ref from props)
104+
// nodeRef is a ref and should not be in dependencies per React best practices
110105
// eslint-disable-next-line react-hooks/exhaustive-deps
111106
}, [getDoc, handleLoad]);
112107

113108
const renderFrameContents = (): ReactNode => {
114-
if (!isMounted.current) {
115-
return null;
116-
}
117-
118109
const doc = getDoc();
119110

120111
if (!doc) {

test/Context.spec.jsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33
import { expect, describe, it } from 'vitest';
4-
import {
5-
FrameContextProvider,
6-
FrameContextConsumer,
7-
useFrame
8-
} from '../src/Context';
4+
import { FrameContextProvider, FrameContextConsumer } from '../src/Context';
5+
import { useFrame } from '../src/useFrame';
96

107
describe('The DocumentContext Component', () => {
118
it('will establish context variables', async () => {

test/Frame.spec.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { render, waitFor } from '@testing-library/react';
33
import { expect, vi, describe, it, afterEach, beforeEach } from 'vitest';
44
import ForwardedRefFrame, { Frame } from '../src/Frame';
5-
import { FrameContext } from '../src/Context';
5+
import { FrameContext } from '../src/FrameContext';
66

77
describe('The Frame Component', () => {
88
let div;

0 commit comments

Comments
 (0)