feat: Implement server-side comment preloading for improved performance and introduce new comment features including pinned comments, locked threads, and custom emojis.
This commit is contained in:
@@ -57,6 +57,38 @@ class CommentSystem {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for server-side preloaded comments
|
||||
// Check for server-side preloaded comments (Script Tag Method)
|
||||
const dataEl = document.getElementById('initial-comments');
|
||||
if (dataEl) {
|
||||
try {
|
||||
// Decode Base64 for safe template transfer
|
||||
const raw = dataEl.textContent.trim();
|
||||
const json = atob(raw);
|
||||
const comments = JSON.parse(json);
|
||||
|
||||
const subEl = document.getElementById('initial-subscription');
|
||||
// Handle boolean text content
|
||||
const isSubscribed = subEl && (subEl.textContent.trim() === 'true');
|
||||
|
||||
// Consume
|
||||
dataEl.remove();
|
||||
if (subEl) subEl.remove();
|
||||
|
||||
this.render(comments, this.user, isSubscribed);
|
||||
|
||||
if (scrollToId) {
|
||||
this.scrollToComment(scrollToId);
|
||||
} else if (window.location.hash && window.location.hash.startsWith('#c')) {
|
||||
const hashId = window.location.hash.substring(2);
|
||||
this.scrollToComment(hashId);
|
||||
}
|
||||
return;
|
||||
} catch (e) {
|
||||
console.error("SSR comments parse error", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Render skeleton (Result: Layout visible immediately)
|
||||
if (!scrollToId) {
|
||||
this.render([], this.user, false);
|
||||
|
||||
Reference in New Issue
Block a user