Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

Commit cc1d6cd

Browse files
MaxGhenisclaude
andcommitted
Address Copilot review comments and fix lint issues
- Import and use useMemo from React - Memoize baseUrl to prevent unnecessary re-renders - Memoize iframeOrigin for efficient message verification - Use location.search from useLocation hook instead of window.location.search - Update useEffect dependencies to use memoized values - Fix code formatting with prettier These changes improve performance by avoiding unnecessary computations and follow React best practices for hooks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 44db38f commit cc1d6cd

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

src/applets/OBBBAHouseholdExplorer.jsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Header from "../layout/Header";
22
import { Helmet } from "react-helmet";
33
import style from "../style";
44
import { useWindowHeight } from "../hooks/useWindow";
5-
import { useEffect, useRef } from "react";
5+
import { useEffect, useRef, useMemo } from "react";
66
import { useNavigate, useLocation } from "react-router-dom";
77

88
export default function OBBBAHouseholdExplorer() {
@@ -11,29 +11,43 @@ export default function OBBBAHouseholdExplorer() {
1111
const location = useLocation();
1212
const iframeRef = useRef(null);
1313

14-
// Get current URL parameters to forward to iframe
15-
const urlParams = new URLSearchParams(window.location.search);
16-
const baseUrl = process.env.REACT_APP_OBBBA_IFRAME_URL || "https://policyengine.github.io/obbba-scatter";
17-
14+
// Memoize baseUrl to prevent unnecessary re-renders
15+
const baseUrl = useMemo(
16+
() =>
17+
process.env.REACT_APP_OBBBA_IFRAME_URL ||
18+
"https://policyengine.github.io/obbba-scatter",
19+
[],
20+
);
21+
22+
// Memoize iframe origin for efficient message verification
23+
const iframeOrigin = useMemo(() => new URL(baseUrl).origin, [baseUrl]);
24+
25+
// Get current URL parameters to forward to iframe using location hook
26+
const urlParams = new URLSearchParams(location.search);
27+
1828
// Construct iframe URL with forwarded parameters
19-
const iframeUrl = urlParams.toString() ? `${baseUrl}?${urlParams.toString()}` : baseUrl;
29+
const iframeUrl = urlParams.toString()
30+
? `${baseUrl}?${urlParams.toString()}`
31+
: baseUrl;
2032

2133
useEffect(() => {
2234
// Listen for messages from the iframe
2335
const handleMessage = (event) => {
2436
// Verify the message is from our iframe
25-
if (event.origin !== new URL(baseUrl).origin) return;
26-
37+
if (event.origin !== iframeOrigin) return;
38+
2739
// Handle URL update messages from the iframe
28-
if (event.data?.type === 'urlUpdate' && event.data?.params) {
40+
if (event.data?.type === "urlUpdate" && event.data?.params) {
2941
const newParams = new URLSearchParams(event.data.params);
30-
navigate(`${location.pathname}?${newParams.toString()}`, { replace: true });
42+
navigate(`${location.pathname}?${newParams.toString()}`, {
43+
replace: true,
44+
});
3145
}
3246
};
3347

34-
window.addEventListener('message', handleMessage);
35-
return () => window.removeEventListener('message', handleMessage);
36-
}, [navigate, location.pathname, baseUrl]);
48+
window.addEventListener("message", handleMessage);
49+
return () => window.removeEventListener("message", handleMessage);
50+
}, [navigate, location.pathname, iframeOrigin]);
3751

3852
return (
3953
<>

0 commit comments

Comments
 (0)