From 91f51cd71f05471c1761fad825996bc9361089ab Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 6 Mar 2026 02:28:50 -0400 Subject: [PATCH] Fix set_flag blocks being dropped after trade_action Bug: trade_order_generators.js set skipAdditionalParsing=true which caused json_base_generator.js to return early before processing sibling blocks. This meant set_flag and other blocks connected after trade_action were silently dropped from the JSON. Fix: Removed the unnecessary skipAdditionalParsing flag. The code path it was meant to protect was already in an else branch, so the flag served no purpose and broke block handling. Also includes minor fixes to Strategies.js and backtesting.js from earlier session work. Co-Authored-By: Claude Opus 4.5 --- src/static/Strategies.js | 16 ++++++++++++++-- src/static/backtesting.js | 6 ++++++ .../blocks/generators/trade_order_generators.js | 3 --- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/static/Strategies.js b/src/static/Strategies.js index 758271f..83ee5d4 100644 --- a/src/static/Strategies.js +++ b/src/static/Strategies.js @@ -1137,12 +1137,24 @@ class StratWorkspaceManager { this.workspace.clear(); Blockly.Xml.domToWorkspace(workspaceXml, this.workspace); } catch (error) { + // Save the failed XML for debugging + const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); + const debugKey = `failed_strategy_xml_${timestamp}`; + try { + localStorage.setItem(debugKey, workspaceXmlText); + console.error(`Failed XML saved to localStorage as "${debugKey}"`); + console.error('To retrieve: localStorage.getItem("' + debugKey + '")'); + } catch (e) { + // If localStorage fails, log to console + console.error('Failed workspace XML (copy for debugging):', workspaceXmlText); + } + if (error instanceof SyntaxError) { console.error('Syntax error in workspace XML:', error.message); - alert('There was a syntax error in the workspace data. Please check the data and try again.'); + alert('There was a syntax error in the workspace data. Please check the data and try again.\n\nDebug XML saved to localStorage as: ' + debugKey); } else { console.error('Unexpected error restoring workspace:', error); - alert('An unexpected error occurred while restoring the workspace.'); + alert('An unexpected error occurred while restoring the workspace.\n\nDebug XML saved to localStorage as: ' + debugKey); } } } diff --git a/src/static/backtesting.js b/src/static/backtesting.js index 4aff9a1..81a5028 100644 --- a/src/static/backtesting.js +++ b/src/static/backtesting.js @@ -514,6 +514,12 @@ class Backtesting { this.setText(this.backtestDraggableHeader, "Create New Backtest"); this.clearForm(); + // Auto-select first strategy AFTER clearForm() to avoid being reset + const strategies = this.getAvailableStrategies(); + if (strategies && strategies.length > 0) { + this.strategyDropdown.value = strategies[0].tbl_key; + } + // Set default start_date to 1 hour ago const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000); // Current time minus 1 hour const formattedDate = this.formatDateToLocalInput(oneHourAgo); diff --git a/src/static/blocks/generators/trade_order_generators.js b/src/static/blocks/generators/trade_order_generators.js index 110d846..a37af62 100644 --- a/src/static/blocks/generators/trade_order_generators.js +++ b/src/static/blocks/generators/trade_order_generators.js @@ -78,9 +78,6 @@ export function defineTradeOrderGenerators() { } } - // **Set the skipAdditionalParsing flag** - json.skipAdditionalParsing = true; - console.log(`Generated JSON for 'trade_action' block:`, json); return json; };