Fix reactive state management to prevent infinite loops
- Implemented debounced graph updates with 100ms delay
- Created derived graphDependencies to track all update triggers in one place
- Added setTimeout to defer state changes in auto-disable logic
- Broke synchronous update cycles that were causing stuttering
- Used updateTimer to prevent multiple simultaneous updates
The graph now updates smoothly without stuttering or infinite loops.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
// Just track the dependencies and schedule update
const deps = graphDependencies;
if (svg && events?.length > 0) {
scheduleGraphUpdate();
}
}
});
});
@ -996,12 +1007,22 @@
/**
/**
* Watch for tag anchor count and auto-disable if exceeds threshold
* Watch for tag anchor count and auto-disable if exceeds threshold
*/
*/
let autoDisableTimer: ReturnType<typeofsetTimeout> | null = null;
$effect(() => {
$effect(() => {
// Clear any pending timer
if (autoDisableTimer) {
clearTimeout(autoDisableTimer);
autoDisableTimer = null;
}
// Only check when tag anchors are shown and we have tags
// Only check when tag anchors are shown and we have tags
if (showTagAnchors && tagAnchorInfo.length > 0) {
if (showTagAnchors && tagAnchorInfo.length > 0) {
// If we have more than MAX_TAG_ANCHORS and haven't auto-disabled yet
// If we have more than MAX_TAG_ANCHORS and haven't auto-disabled yet
if (tagAnchorInfo.length > MAX_TAG_ANCHORS && !autoDisabledTags) {
if (tagAnchorInfo.length > MAX_TAG_ANCHORS && !autoDisabledTags) {
// Defer the state update to break the sync cycle
autoDisableTimer = setTimeout(() => {
debug(`Auto-disabling tags: ${tagAnchorInfo.length} exceeds maximum of ${MAX_TAG_ANCHORS}`);
debug(`Auto-disabling tags: ${tagAnchorInfo.length} exceeds maximum of ${MAX_TAG_ANCHORS}`);
// Disable all tags
// Disable all tags
@ -1016,17 +1037,22 @@
// Optional: Show a notification to the user
// Optional: Show a notification to the user
console.info(`[EventNetwork] Auto-disabled ${tagAnchorInfo.length} tag anchors to prevent graph overload. Click individual tags in the legend to enable them.`);
console.info(`[EventNetwork] Auto-disabled ${tagAnchorInfo.length} tag anchors to prevent graph overload. Click individual tags in the legend to enable them.`);
}, 0);
}
}
// Reset auto-disabled flag if tag count goes back down
// Reset auto-disabled flag if tag count goes back down
if (tagAnchorInfo.length <= MAX_TAG_ANCHORS && autoDisabledTags) {
if (tagAnchorInfo.length <= MAX_TAG_ANCHORS && autoDisabledTags) {