Fixes #7: Rendering performance optimizations
- requestAnimationFrame batching: rerenderRpgState() now batches all render calls into a single animation frame, reducing reflow/repaint costs - Lightweight change detection: Render functions use updateIfChanged() to skip DOM updates when content hasn't changed, and only re-bind event handlers when the DOM was actually updated - CSS content-visibility: Added content-visibility: auto with contain-intrinsic-size to inventory and equipment containers, deferring rendering of off-screen content New file: src/systems/rendering/renderUtils.js (rendering utilities module) Updated: All render modules + sillytavern.js integration + style.css
This commit is contained in:
1 parent
1f8591d4ec
commit
24c964c38d
9 files changed
+239
-40
No files matched your search
@@ -10,6 +10,7 @@ import { updateInventoryItem } from '../interaction/inventoryEdit.js';
|
||||
import { parseItems } from '../../utils/itemParser.js';
|
||||
import { isItemLocked, setItemLock } from '../generation/lockManager.js';
|
||||
import { i18n } from '../../core/i18n.js';
|
||||
import { updateIfChanged } from './renderUtils.js';
|
||||
|
||||
// Type imports
|
||||
/** @typedef {import('../../types/inventory.js').InventoryV2} InventoryV2 */
|
||||
@@ -594,13 +595,15 @@ export function renderInventory() {
|
||||
|
||||
// Generate HTML and update DOM
|
||||
const html = generateInventoryHTML(inventory, options);
|
||||
$inventoryContainer.html(html);
|
||||
const domUpdated = updateIfChanged($inventoryContainer, html, 'rpg-inventory');
|
||||
|
||||
// Restore form states after re-rendering (fixes Bug #1)
|
||||
restoreFormStates();
|
||||
|
||||
// Event listener for editing item names (mobile-friendly contenteditable)
|
||||
$inventoryContainer.find('.rpg-item-name.rpg-editable').on('blur', function() {
|
||||
// Only re-bind event handlers if DOM was actually updated
|
||||
if (domUpdated) {
|
||||
// Event listener for editing item names (mobile-friendly contenteditable)
|
||||
$inventoryContainer.find('.rpg-item-name.rpg-editable').on('blur', function() {
|
||||
const field = $(this).data('field');
|
||||
const index = parseInt($(this).data('index'));
|
||||
const location = $(this).data('location');
|
||||
@@ -632,6 +635,7 @@ export function renderInventory() {
|
||||
// Save settings
|
||||
saveSettings();
|
||||
});
|
||||
} // end if (domUpdated)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user