From 8f5b4215316af505b5ec227282de5e88ca95debf Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 10 Oct 2024 08:34:24 +1300 Subject: [PATCH] Fix infinite loop --- .../homebrew/editor/snippetbar/snippetbar.jsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index 503596236..429dfd1b6 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -5,7 +5,7 @@ const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); -import { historyCheck, loadHistory } from '../../utils/versionHistory.js'; +import { loadHistory } from '../../utils/versionHistory.js'; //Import all themes const ThemeSnippets = {}; @@ -70,23 +70,27 @@ const Snippetbar = createClass({ }); }; - const checkHistoryExists = (await historyCheck(this.props.brew)) ?? false; - if(checkHistoryExists != prevState.historyExists){ + // Update history list if it has changed + const checkHistoryItems = await loadHistory(this.props.brew); + + // If all items have the noData property, there is no saved data + const checkHistoryExists = !checkHistoryItems.every((historyItem)=>{ + return historyItem?.noData; + }); + if(prevState.historyExists != checkHistoryExists){ this.setState({ historyExists : checkHistoryExists }); } - // Update history list if it has changed - const checkHistoryItems = await loadHistory(this.props.brew); - if(checkHistoryItems.some((historyItem, index)=>{ - return !index < this.state.historyItems.length || historyItem != this.state.historyItems[index]; + // If any history items have changed, update the list + if(checkHistoryExists && checkHistoryItems.some((historyItem, index)=>{ + return index >= prevState.historyItems.length || !_.isEqual(historyItem, prevState.historyItems[index]); })){ this.setState({ historyItems : checkHistoryItems }); } - }, mergeCustomizer : function(oldValue, newValue, key) {