Skip to content

Prevent unbounded z-index growth in draggable items#314

Merged
Edwardvaneechoud merged 2 commits intomainfrom
claude/fix-modal-z-index-6VQRh
Feb 6, 2026
Merged

Prevent unbounded z-index growth in draggable items#314
Edwardvaneechoud merged 2 commits intomainfrom
claude/fix-modal-z-index-6VQRh

Conversation

@Edwardvaneechoud
Copy link
Copy Markdown
Owner

Summary

This PR implements z-index management improvements to prevent unbounded growth of z-index values in the draggable item store. Z-index values are now constrained within defined ranges and automatically normalized when they exceed safe limits.

Key Changes

  • Added z-index constants: Introduced BASE_Z_INDEX (100), MAX_Z_INDEX (200), and FULLSCREEN_Z_INDEX (250) to replace magic numbers and establish clear boundaries
  • Implemented z-index normalization: Added normalizeZIndices() function that resets non-fullscreen items to sequential z-index values starting from BASE_Z_INDEX when values exceed MAX_Z_INDEX
  • Enhanced bringToFront() logic:
    • Added early return if item is already at the top
    • Triggers normalization when z-index would exceed MAX_Z_INDEX
    • Simplified to only save state when normalization doesn't occur
  • Fixed localStorage restoration: Added clamping of restored z-index values to prevent inflated values persisted in localStorage from causing issues
  • Refactored clickOnItem(): Now delegates to bringToFront() to avoid code duplication and ensure consistent z-index management
  • Simplified fullscreen exit: Removed hardcoded z-index values and now properly restores items to base state before bringing the exiting item to front
  • Updated intersection observer: Uses bringToFront() instead of direct z-index manipulation for consistency

Implementation Details

  • Z-index normalization only affects non-fullscreen items, preserving fullscreen items at FULLSCREEN_Z_INDEX
  • The normalization process maintains the relative stacking order while resetting absolute values
  • All magic number z-index values (99, 100, 1000, 9999) have been replaced with named constants for maintainability

https://claude.ai/code/session_01QnbcTGngNwdbBWVX9BT4Un

The bringToFront() and clickOnItem() functions incremented z-index on
every click without any upper bound. These values persisted to
localStorage, causing z-index values to grow into the hundreds/thousands
across sessions and eventually overlap with modals, tooltips, and
context menus.

Changes:
- Add BASE_Z_INDEX (100), MAX_Z_INDEX (200), FULLSCREEN_Z_INDEX (250)
  constants to bound the z-index range
- Skip incrementing if the panel is already the topmost
- Add normalizeZIndices() that compresses all panel z-indices back into
  [100, 100+n] when they exceed MAX_Z_INDEX
- Clamp z-index values restored from localStorage to prevent inflated
  values from persisting
- Deduplicate clickOnItem() to delegate to bringToFront()
- Use bounded constants for fullscreen z-index (was 9999)

https://claude.ai/code/session_01QnbcTGngNwdbBWVX9BT4Un
@netlify
Copy link
Copy Markdown

netlify bot commented Feb 6, 2026

Deploy Preview for flowfile-wasm canceled.

Name Link
🔨 Latest commit b021b70
🔍 Latest deploy log https://app.netlify.com/projects/flowfile-wasm/deploys/6985fa43e18fbc0008f463e4

The previous change accidentally included the current item in the max
z-index calculation and used >= comparison. This meant when all panels
had the same z-index (initial state, after normalization, or after
exiting fullscreen), no panel could be brought to front since its own
z-index always equaled the max.

Fix: exclude the current item (itemId !== id) from max calculation and
use strict > for the "already on top" guard.

https://claude.ai/code/session_01QnbcTGngNwdbBWVX9BT4Un
@Edwardvaneechoud Edwardvaneechoud merged commit e370315 into main Feb 6, 2026
17 checks passed
@Edwardvaneechoud Edwardvaneechoud deleted the claude/fix-modal-z-index-6VQRh branch February 6, 2026 14:47
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.

2 participants