Fix board reloading page every second.

Thanks to xet7 !
This commit is contained in:
Lauri Ojansivu 2025-10-23 04:03:52 +03:00
parent ef19c35b5a
commit b4b598f542

View file

@ -17,6 +17,8 @@ BlazeComponent.extendComponent({
this.isConverting = new ReactiveVar(false); this.isConverting = new ReactiveVar(false);
this.isMigrating = new ReactiveVar(false); this.isMigrating = new ReactiveVar(false);
this._swimlaneCreated = new Set(); // Track boards where we've created swimlanes this._swimlaneCreated = new Set(); // Track boards where we've created swimlanes
this._boardProcessed = false; // Track if board has been processed
this._lastProcessedBoardId = null; // Track last processed board ID
// The pattern we use to manually handle data loading is described here: // The pattern we use to manually handle data loading is described here:
// https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager // https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
@ -28,21 +30,33 @@ BlazeComponent.extendComponent({
const handle = subManager.subscribe('board', currentBoardId, false); const handle = subManager.subscribe('board', currentBoardId, false);
Tracker.nonreactive(() => { // Use a separate autorun for subscription ready state to avoid reactive loops
Tracker.autorun(() => { this.subscriptionReadyAutorun = Tracker.autorun(() => {
if (handle.ready()) { if (handle.ready()) {
// Only run conversion/migration logic once per board
if (!this._boardProcessed || this._lastProcessedBoardId !== currentBoardId) {
this._boardProcessed = true;
this._lastProcessedBoardId = currentBoardId;
// Ensure default swimlane exists (only once per board) // Ensure default swimlane exists (only once per board)
this.ensureDefaultSwimlane(currentBoardId); this.ensureDefaultSwimlane(currentBoardId);
// Check if board needs conversion // Check if board needs conversion
this.checkAndConvertBoard(currentBoardId); this.checkAndConvertBoard(currentBoardId);
} else {
this.isBoardReady.set(false);
} }
}); } else {
this.isBoardReady.set(false);
}
}); });
}); });
}, },
onDestroyed() {
// Clean up the subscription ready autorun to prevent memory leaks
if (this.subscriptionReadyAutorun) {
this.subscriptionReadyAutorun.stop();
}
},
ensureDefaultSwimlane(boardId) { ensureDefaultSwimlane(boardId) {
// Only create swimlane once per board // Only create swimlane once per board
if (this._swimlaneCreated.has(boardId)) { if (this._swimlaneCreated.has(boardId)) {
@ -441,39 +455,50 @@ BlazeComponent.extendComponent({
this._isDragging = false; this._isDragging = false;
// Used to set the overlay // Used to set the overlay
this.mouseHasEnterCardDetails = false; this.mouseHasEnterCardDetails = false;
this._sortFieldsFixed = new Set(); // Track which boards have had sort fields fixed
// fix swimlanes sort field if there are null values // fix swimlanes sort field if there are null values
const currentBoardData = Utils.getCurrentBoard(); const currentBoardData = Utils.getCurrentBoard();
if (currentBoardData && Swimlanes) { if (currentBoardData && Swimlanes) {
const nullSortSwimlanes = currentBoardData.nullSortSwimlanes(); const boardId = currentBoardData._id;
if (nullSortSwimlanes.length > 0) { // Only fix sort fields once per board to prevent reactive loops
const swimlanes = currentBoardData.swimlanes(); if (!this._sortFieldsFixed.has(`swimlanes-${boardId}`)) {
let count = 0; const nullSortSwimlanes = currentBoardData.nullSortSwimlanes();
swimlanes.forEach(s => { if (nullSortSwimlanes.length > 0) {
Swimlanes.update(s._id, { const swimlanes = currentBoardData.swimlanes();
$set: { let count = 0;
sort: count, swimlanes.forEach(s => {
}, Swimlanes.update(s._id, {
$set: {
sort: count,
},
});
count += 1;
}); });
count += 1; }
}); this._sortFieldsFixed.add(`swimlanes-${boardId}`);
} }
} }
// fix lists sort field if there are null values // fix lists sort field if there are null values
if (currentBoardData && Lists) { if (currentBoardData && Lists) {
const nullSortLists = currentBoardData.nullSortLists(); const boardId = currentBoardData._id;
if (nullSortLists.length > 0) { // Only fix sort fields once per board to prevent reactive loops
const lists = currentBoardData.lists(); if (!this._sortFieldsFixed.has(`lists-${boardId}`)) {
let count = 0; const nullSortLists = currentBoardData.nullSortLists();
lists.forEach(l => { if (nullSortLists.length > 0) {
Lists.update(l._id, { const lists = currentBoardData.lists();
$set: { let count = 0;
sort: count, lists.forEach(l => {
}, Lists.update(l._id, {
$set: {
sort: count,
},
});
count += 1;
}); });
count += 1; }
}); this._sortFieldsFixed.add(`lists-${boardId}`);
} }
} }
}, },