From b11c8aed1e428539422a0985dc125cd8fa48e86c Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 7 Dec 2025 01:09:30 -0500 Subject: [PATCH] Fix Google Charts not rendering with Turbolinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed $(document).ready() wrapper inside google.load callback which was preventing charts from rendering when page loaded via Turbolinks. Changes: - Remove document.ready wrapper (DOM already ready with Turbolinks) - Add check for element existence before drawing chart - Add guard to verify google.load exists before calling - Create separate initializeChart function for cleaner callback This ensures charts render properly on Turbolinks page loads where the DOM is already ready when the script executes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/views/performance/index.html.erb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/views/performance/index.html.erb b/app/views/performance/index.html.erb index f6ff62b..d5aa3a5 100644 --- a/app/views/performance/index.html.erb +++ b/app/views/performance/index.html.erb @@ -120,15 +120,22 @@ function makeActive(){ $('li[id="performance"]').addClass('active'); }; -// Load Google Charts and set callback -google.load("visualization", "1", { - packages: ["corechart"], - callback: function() { - $(document).ready(function () { - drawChart2(); - makeActive(); - }); +function initializeChart() { + // Check if element exists before drawing + if (document.getElementById('line_chart')) { + drawChart2(); } -}); + makeActive(); +} + +// Load Google Charts and set callback +if (typeof google !== 'undefined' && google.load) { + google.load("visualization", "1", { + packages: ["corechart"], + callback: initializeChart + }); +} else { + console.error('Google JSAPI not loaded'); +} \ No newline at end of file