svelte-lexical icon indicating copy to clipboard operation
svelte-lexical copied to clipboard

Error in running playground demo

Open pan2za opened this issue 1 year ago • 1 comments

The debugging info: TreeView.svelte:184 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length') at generateContent (TreeView.svelte:184:20) at $$self.$$.update (TreeView.svelte:68:15) at init (Component.js:144:5) at new TreeView (TreeView.svelte:97:26) at create_fragment91 (TreeView.svelte:97:26) at init (Component.js:148:34) at new TreeViewPlugin (TreeView.svelte:97:26) at create_if_block (RichTextComposer.svelte:163:54) at Object.update [as p] (RichTextComposer.svelte:172:32) at update_slot_base (utils.js:203:8)

demo from playground. Code from 20240925 Reproduction: 1 run the playground demo 2 goto setting button 3 turn on debug view bar 4 turn off debug view bar then the error found in the console.

How to resolve: function generateContent( editor: LexicalEditor, commandsLog: ReadonlyArray< {index: number} & LexicalCommand & {payload: unknown}

, exportDOM: boolean, ): string { // 在这里实现你的生成内容逻辑 // 假设这里的代码可能会导致 TypeError }

// 在调用 generateContent 之前进行检查 if (editor && commandsLog !== undefined) { <<---------should add undefined checking ? if (Array.isArray(commandsLog) && commandsLog.length > 0) { const content = generateContent(editor, commandsLog, exportDOM); // 使用生成的内容 } else { console.error('commandsLog is not an array or is empty.'); } } else { console.error('editor or commandsLog is undefined.'); }

pan2za avatar Sep 25 '24 03:09 pan2za

Hi @pan2za ,

Thanks for reporting this issue and suggesting a fix.

I have pushed a commit to resolve, could you please verify?

umaranis avatar Sep 25 '24 05:09 umaranis