Skip to content

Commit 85205c1

Browse files
fix: improve marker width calculation for server-side rendering (#801)
* fix: improve marker width calculation for server-side rendering * refactor: replace console.log with #log for improved logging consistency in SuperDoc --------- Co-authored-by: Caio Pizzol <caiopizzol@icloud.com>
1 parent 62daad3 commit 85205c1

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

packages/super-editor/src/extensions/list-item/ListItemNodeView.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ function calculateMarkerWidth(dom, numberingDOM, { withPadding = true } = {}) {
357357

358358
if (!markerText.trim()) return 0;
359359

360+
// Check if canvas is available (browser environment)
361+
if (typeof document === 'undefined' || !document.createElement('canvas').getContext) {
362+
// Simple estimation for server-side: ~8px per character
363+
const textWidth = markerText.length * 8;
364+
return withPadding ? textWidth + MARKER_PADDING : textWidth;
365+
}
366+
360367
try {
361368
const canvas = document.createElement('canvas');
362369
const context = canvas.getContext('2d');

packages/superdoc/src/core/SuperDoc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,12 @@ export class SuperDoc extends EventEmitter {
807807
async #triggerCollaborationSaves() {
808808
this.#log('🦋 [superdoc] Triggering collaboration saves');
809809
return new Promise((resolve) => {
810-
this.superdocStore.documents.forEach((doc) => {
810+
this.superdocStore.documents.forEach((doc, index) => {
811+
this.#log(`Before reset - Doc ${index}: pending = ${this.pendingCollaborationSaves}`);
811812
this.pendingCollaborationSaves = 0;
812813
if (doc.ydoc) {
813814
this.pendingCollaborationSaves++;
815+
this.#log(`After increment - Doc ${index}: pending = ${this.pendingCollaborationSaves}`);
814816
const metaMap = doc.ydoc.getMap('meta');
815817
metaMap.observe((event) => {
816818
if (event.changes.keys.has('immediate-save-finished')) {
@@ -823,6 +825,9 @@ export class SuperDoc extends EventEmitter {
823825
metaMap.set('immediate-save', true);
824826
}
825827
});
828+
this.#log(
829+
`FINAL pending = ${this.pendingCollaborationSaves}, but we have ${this.superdocStore.documents.filter((d) => d.ydoc).length} docs!`,
830+
);
826831
});
827832
}
828833

0 commit comments

Comments
 (0)