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

Error in running playground demo #94

Open
pan2za opened this issue Sep 25, 2024 · 1 comment
Open

Error in running playground demo #94

pan2za opened this issue Sep 25, 2024 · 1 comment

Comments

@pan2za
Copy link

pan2za commented Sep 25, 2024

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.');
}

@umaranis
Copy link
Owner

Hi @pan2za ,

Thanks for reporting this issue and suggesting a fix.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants