@@ -477,6 +477,9 @@ def __init__(self, *args, **kwargs):
477477 self ._path_info = get_python_path_info ()
478478 self .stats = {}
479479
480+ # Opcode collection flag
481+ self .opcodes_enabled = False
482+
480483 # Template loader (loads all templates once)
481484 self ._template_loader = _TemplateLoader ()
482485
@@ -528,6 +531,8 @@ def process_frames(self, frames, thread_id):
528531 self ._record_line_sample (filename , lineno , funcname , is_leaf = (i == 0 ))
529532
530533 if opcode is not None :
534+ # Set opcodes_enabled flag when we first encounter opcode data
535+ self .opcodes_enabled = True
531536 self ._record_bytecode_sample (filename , lineno , opcode ,
532537 end_lineno , col_offset , end_col_offset )
533538
@@ -953,6 +958,9 @@ def _build_line_html(self, line_num: int, line_content: str,
953958 f'onclick="toggleBytecode(this)" title="Show bytecode">▶</button>'
954959 )
955960 bytecode_panel_html = f' <div class="bytecode-panel" id="bytecode-{ line_num } " style="display:none;"></div>\n '
961+ elif self .opcodes_enabled :
962+ # Add invisible spacer to maintain consistent indentation when opcodes are enabled
963+ bytecode_btn_html = '<div class="bytecode-spacer"></div>'
956964
957965 # Get navigation buttons
958966 nav_buttons_html = self ._build_navigation_buttons (filename , line_num )
0 commit comments