Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] Fix(debug): remove component in beforeDestroy hook #6756

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
40 changes: 6 additions & 34 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import { extensionHighlight } from '../helpers/mappings.js'
import { createEditor, serializePlainText, loadSyntaxHighlight } from './../EditorFactory.js'
import { createMarkdownSerializer } from './../extensions/Markdown.js'
import markdownit from './../markdownit/index.js'

import { exposeForDebugging, removeFromDebugging } from '../helpers/debug.js'
import { CollaborationCursor } from '../extensions/index.js'
import DocumentStatus from './Editor/DocumentStatus.vue'
import isMobile from './../mixins/isMobile.js'
Expand Down Expand Up @@ -351,7 +351,7 @@ export default {
subscribe('text:image-node:add', this.onAddImageNode)
subscribe('text:image-node:delete', this.onDeleteImageNode)
this.emit('update:loaded', true)
this.setupEditorDebug()
exposeForDebugging(this)
},
created() {
this.$ydoc = new Doc()
Expand All @@ -377,7 +377,8 @@ export default {
const timeout = new Promise((resolve) => setTimeout(resolve, 2000))
await Promise.any([timeout, this.$syncService.save()])
}
this.close()
await this.close()
removeFromDebugging(this)
},
methods: {
initSession() {
Expand Down Expand Up @@ -762,46 +763,17 @@ export default {
console.debug(editor.getHTML())
},

/**
* Setup OCA.Text.debugYjs() and expose editor component in OCA.Text.editorComponents
*/
setupEditorDebug() {
if (!window.OCA.Text) {
window.OCA.Text = {}
}
if (!window.OCA.Text.editorComponents) {
window.OCA.Text.editorComponents = []
}
window.OCA.Text.editorComponents.push(this)

if (!window.OCA.Text.debugYjs) {
window.OCA.Text.debugYjs = () => {
const intro = 'Editor Yjs debug data. Copy the objects above that start with "fileId".'
const introChrome = '- In Chrome, select "Copy" at the end of the line.'
const introFirefox = '- In Firefox, right-click on the object and select "Copy object".'
const styleBold = 'font-weight: bold;'
const styleItalic = 'font-weight: normal; font-style: italic;'

for (const editorComponent of window.OCA.Text.editorComponents) {
console.warn(JSON.stringify(editorComponent.debugYjsData(), null, ' '))
}

console.warn('%c%s\n%c%s\n%s', styleBold, intro, styleItalic, introChrome, introFirefox)
}
}
},

/**
* Helper method to debug yjs issues
*/
debugYjsData() {
debugData() {
const yjsData = {
fileId: this.fileId,
filePath: this.relativePath,
clientId: this.$ydoc.clientID,
pendingStructs: this.$ydoc.store.pendingStructs,
clientVectors: [],
documentState: this.$syncService.getDocumentState(),
documentState: this.$syncService?.getDocumentState(),
}
for (const client of this.$ydoc.store.clients.values()) {
yjsData.clientVectors.push(client.at(-1).id)
Expand Down
52 changes: 52 additions & 0 deletions src/helpers/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

/**
* Setup OCA.Text.debugYjs() and expose editor component in OCA.Text.editorComponents
*/

if (!window.OCA.Text) {
window.OCA.Text = {}
}

const editorComponents = window.OCA.Text.editorComponents ?? new Set()
window.OCA.Text.editorComponents = editorComponents

/**
* Print debug info for all editor components as a warning.
*/
export function debugYjs() {
const intro = 'Editor Yjs debug data. Copy the objects above that start with "fileId".'
const introChrome = '- In Chrome, select "Copy" at the end of the line.'
const introFirefox = '- In Firefox, right-click on the object and select "Copy object".'
const styleBold = 'font-weight: bold;'
const styleItalic = 'font-weight: normal; font-style: italic;'

for (const editorComponent of editorComponents.values()) {
console.warn(JSON.stringify(editorComponent.debugData(), null, ' '))
}

console.warn('%c%s\n%c%s\n%s', styleBold, intro, styleItalic, introChrome, introFirefox)
}

if (!window.OCA.Text.debugYjs) {
window.OCA.Text.debugYjs = debugYjs
}

/**
* Expose editor component in OCA.Text.editorComponents
* @param {object} component - the editor component to include in debug output
*/
export function exposeForDebugging(component) {
editorComponents.add(component)
}

/**
* Drop editor component from OCA.Text.editorComponents
* @param {object} component - the editor component to remove from debug output
*/
export function removeFromDebugging(component) {
editorComponents.delete(component)
}
Loading