Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-24 - Avoid Object Serialization in DOM Attributes
**Learning:** During list rendering (`createPDFCard`), executing `JSON.stringify(object).replace(...)` to pass an entire object to an `onclick` inline handler creates massive performance overhead. Not only is serialization expensive, but it also generates huge string sizes in the DOM resulting in increased memory use.
**Action:** Instead of inline full-object serialization, pass a simple unique ID (`data-id="123"`) and rely on the event handler (`viewPDF(id)`) to look up the object reference in the data store (`pdfDatabase`).
13 changes: 10 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,13 @@ function getEmbeddableUrl(url) {
return `https://docs.google.com/gview?embedded=true&url=${encodeURIComponent(url)}`;
}

async function viewPDF(pdf, pushToHistory = true) {
async function viewPDF(pdfOrId, pushToHistory = true) {
let pdf = pdfOrId;
if (typeof pdfOrId === 'string') {
pdf = pdfDatabase.find(p => p.id === pdfOrId);
}
if (!pdf) return;

const originalPdfPath = pdf.pdfUrl;
logInteraction('view_pdf', pdf.title, pdf.id);

Expand Down Expand Up @@ -1020,7 +1026,8 @@ function createPDFCard(pdf, favoritesList, index = 0, highlightRegex = null) {
return safeText.replace(highlightRegex, '<span class="highlight">$1</span>');
};

const safePdfString = JSON.stringify(pdf).replace(/"/g, '&quot;');
// ⚑ Bolt Performance Optimization: Removed expensive JSON.stringify(pdf) which was running for every card.
// Now we just pass the PDF ID and let viewPDF handle the lookup.

// --- NEW: Calculate Stagger Delay ---
// Cap at 1s (20 items) so the list doesn't feel unresponsive
Expand All @@ -1037,7 +1044,7 @@ function createPDFCard(pdf, favoritesList, index = 0, highlightRegex = null) {
</div>
<p class="pdf-description">${highlightText(pdf.description)}</p>
<div class="pdf-actions">
<button class="btn btn-primary" onclick="viewPDF(${safePdfString})">
<button class="btn btn-primary" data-id="${pdf.id}" onclick="viewPDF(this.dataset.id)">
<i class="fas fa-eye"></i> View
</button>
<button class="btn btn-favorite ${btnActiveClass}" onclick="toggleFavorite(event, '${pdf.id}')" title="Save Note">
Expand Down