Skip to content

Fix chart indicators disappearing in fullscreen#67

Open
softsideof wants to merge 2 commits intoOpen-Dev-Society:mainfrom
softsideof:fix-49-preserve-chart-indicators
Open

Fix chart indicators disappearing in fullscreen#67
softsideof wants to merge 2 commits intoOpen-Dev-Society:mainfrom
softsideof:fix-49-preserve-chart-indicators

Conversation

@softsideof
Copy link
Copy Markdown

@softsideof softsideof commented Apr 22, 2026

Summary

  • keep TradingView chart widgets mounted when toggling fullscreen
  • resize the existing widget container instead of reinitializing the embed, which preserves indicator state

Test plan

  • npx eslint components/TradingViewWidget.tsx hooks/useTradingViewWidget.tsx
  • npx tsc --noEmit (currently fails on pre-existing errors in lib/inngest/functions.ts; not caused by this change)

Fixes #49

Summary by CodeRabbit

  • Refactor
    • Removed dynamic window resize listeners for cleaner height tracking in TradingView widget
    • Consolidated responsive height styling from nested widget to outer container
    • Widget now uses expanded state to toggle between standard and full-viewport height display
    • Streamlined dependency management to improve component rendering efficiency

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 22, 2026

@keshav-005 is attempting to deploy a commit to the ravixalgorithm's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d60000f-b9f1-488a-a60a-df61792ee6ed

📥 Commits

Reviewing files that changed from the base of the PR and between c09e3cf and daa6f1b.

📒 Files selected for processing (1)
  • components/TradingViewWidget.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/TradingViewWidget.tsx

📝 Walkthrough

Walkthrough

The PR removes height management from the TradingView hook and component: the hook signature drops the height parameter and stops producing height-based markup; the component moves height styling to its outer container, removes an inner wrapper, and calls the hook with (scriptUrl, widgetConfig) only. Config is serialized once in the hook.

Changes

Cohort / File(s) Summary
Widget component
components/TradingViewWidget.tsx
Removed window resize listener and computed currentHeight; moved height styling to outer container (style={{ height: isExpanded ? '100vh' : height }}); eliminated nested widget wrapper; call to useTradingViewWidget now uses (scriptUrl, widgetConfig) only.
Hook: useTradingViewWidget
hooks/useTradingViewWidget.tsx
Dropped height parameter from signature; always creates widget container with height: 100%; serialize config once (serializedConfig = JSON.stringify(config)) and use in effect deps [scriptUrl, serializedConfig]; cleanup unchanged.

Sequence Diagram(s)

(Skipped — changes are refactor/logic simplification, not a new multi-component control flow.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped along the code today,

Moved heights outside where they may stay,
No more inner wrappers to confound,
Widgets snugly fill the ground,
A joyful twitch, the charts all play.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly addresses the main issue: preventing chart indicators from disappearing when entering fullscreen mode, which is the core objective of the changeset.
Linked Issues check ✅ Passed The code changes successfully address issue #49 by preserving the TradingView widget container instead of reinitializing it during fullscreen transitions, which prevents indicator state loss.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the chart indicators disappearing issue: removing height tracking from component, simplifying the hook signature, and applying responsive height styling to the container.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/TradingViewWidget.tsx (1)

18-31: ⚠️ Potential issue | 🟡 Minor

Initial render has currentHeight = 0 until post-mount effect fires.

windowHeight is initialized to 0, so on the first client render the chart container gets style={{ height: 0 }} before the useEffect updates it. Since the TradingView embed runs inside this same container with height: 100%, users will see a zero-height flash, and in StrictMode the widget may also initialize against a zero-height parent.

Two simple options:

♻️ Fallback to `height` prop until window size is known
-    const currentHeight = isExpanded ? windowHeight : height;
+    const currentHeight = isExpanded ? (windowHeight || height) : height;

Alternatively, lazy-initialize state from window:

-    const [windowHeight, setWindowHeight] = useState(0);
-
-    useEffect(() => {
-        if (typeof window !== 'undefined') {
-            setWindowHeight(window.innerHeight);
-            const handleResize = () => setWindowHeight(window.innerHeight);
-            window.addEventListener('resize', handleResize);
-            return () => window.removeEventListener('resize', handleResize);
-        }
-    }, []);
+    const [windowHeight, setWindowHeight] = useState(() =>
+        typeof window !== 'undefined' ? window.innerHeight : height
+    );
+
+    useEffect(() => {
+        const handleResize = () => setWindowHeight(window.innerHeight);
+        window.addEventListener('resize', handleResize);
+        return () => window.removeEventListener('resize', handleResize);
+    }, []);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/TradingViewWidget.tsx` around lines 18 - 31, TradingViewWidget
currently initializes windowHeight to 0 causing currentHeight to be 0 on first
render; fix by ensuring windowHeight is seeded or currentHeight falls back to
the height prop until the effect runs — e.g. lazy-initialize windowHeight via
useState(() => typeof window !== 'undefined' ? window.innerHeight : height) or
compute currentHeight as isExpanded ? (windowHeight || height) : height; update
references to windowHeight/currentHeight and keep the existing useEffect and
setWindowHeight logic.
🧹 Nitpick comments (1)
components/TradingViewWidget.tsx (1)

65-69: Consider 100vh in expanded mode rather than a px value.

When expanded, currentHeight = windowHeight (px) is applied to a fixed inset-0 subtree that already stretches to the viewport. Using 100vh (or letting h-full win by not setting inline height) is more robust against mobile URL-bar resize, avoids one extra render after the resize listener fires, and removes the need to track windowHeight at all for the fullscreen case.

-                <div
-                    className={cn('tradingview-widget-container', className, isExpanded && "h-full")}
-                    ref={containerRef}
-                    style={{ height: currentHeight, width: "100%" }}
-                />
+                <div
+                    className={cn('tradingview-widget-container', className, isExpanded && "h-full")}
+                    ref={containerRef}
+                    style={{ height: isExpanded ? '100vh' : height, width: "100%" }}
+                />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/TradingViewWidget.tsx` around lines 65 - 69, The inline style
always sets height: currentHeight (px) even when isExpanded is true; change the
TradingViewWidget render so the containerRef div does not set a pixel height
when isExpanded — either set style.height to '100vh' when isExpanded or omit the
height key entirely so the 'h-full' class can control sizing. Update the JSX
around the div that uses className, isExpanded, currentHeight and containerRef
to conditionally apply the inline height only for non-expanded mode and remove
reliance on windowHeight for the fullscreen case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@components/TradingViewWidget.tsx`:
- Around line 18-31: TradingViewWidget currently initializes windowHeight to 0
causing currentHeight to be 0 on first render; fix by ensuring windowHeight is
seeded or currentHeight falls back to the height prop until the effect runs —
e.g. lazy-initialize windowHeight via useState(() => typeof window !==
'undefined' ? window.innerHeight : height) or compute currentHeight as
isExpanded ? (windowHeight || height) : height; update references to
windowHeight/currentHeight and keep the existing useEffect and setWindowHeight
logic.

---

Nitpick comments:
In `@components/TradingViewWidget.tsx`:
- Around line 65-69: The inline style always sets height: currentHeight (px)
even when isExpanded is true; change the TradingViewWidget render so the
containerRef div does not set a pixel height when isExpanded — either set
style.height to '100vh' when isExpanded or omit the height key entirely so the
'h-full' class can control sizing. Update the JSX around the div that uses
className, isExpanded, currentHeight and containerRef to conditionally apply the
inline height only for non-expanded mode and remove reliance on windowHeight for
the fullscreen case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7ce9fb56-8af2-48e0-8e04-7cecf3b6aa8f

📥 Commits

Reviewing files that changed from the base of the PR and between fe59884 and c09e3cf.

📒 Files selected for processing (2)
  • components/TradingViewWidget.tsx
  • hooks/useTradingViewWidget.tsx

@softsideof
Copy link
Copy Markdown
Author

Thanks, updated. Fullscreen now uses viewport height, so the widget no longer initializes against a zero-height container.

@keshav-005
Copy link
Copy Markdown

Closing this in favor of #68 so the contribution is tracked under my main account.

@keshav-005
Copy link
Copy Markdown

Superseded by #68, which is the same fix reopened from my main account. Please use that PR for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indicators disappear when going full screen

2 participants