fix: Cannot read properties of undefined (reading 'length') #13

Closed
nikoPLP wants to merge 1 commit from master into master
nikoPLP commented 2024-08-06 08:23:59 +02:00 (Migrated from github.com)

Hello,
It seems like this.modules[j++].rules on line 122 of style.mod.js can be undefined sometimes. At least it happened here when I am using Codemirror that is inside plugin-split-editing of milkdown.

Anyway. It should be protected to deal with such case.
This PR is a proposed fix.
Let me know if it can be merged soon and a new version tagged and released. thanks.

Hello, It seems like `this.modules[j++].rules` on line 122 of style.mod.js can be undefined sometimes. At least it happened here when I am using Codemirror that is inside [plugin-split-editing of milkdown](https://github.com/enpitsuLin/milkdown-lab/tree/master/packages/plugin-split-editing). Anyway. It should be protected to deal with such case. This PR is a proposed fix. Let me know if it can be merged soon and a new version tagged and released. thanks.
marijnh commented 2024-08-06 08:30:13 +02:00 (Migrated from github.com)

If there's a bug that causes that array to be maintained incorrectly, I'll want to diagnose the bug rather than paper it over with a null check. Can you set up a minimal script that triggers this error?

If there's a bug that causes that array to be maintained incorrectly, I'll want to diagnose the bug rather than paper it over with a null check. Can you set up a minimal script that triggers this error?
nikoPLP commented 2024-08-06 09:00:29 +02:00 (Migrated from github.com)

You are right.
I just didn't have time to read more of your code and to find out why it is reaching such condition.
And for the reproducible test, I cannot easily give you something as it is not from my code.
As I said, there is a CodeMirror inside this plugin of milkdown and the error comes when I am using it, with the default setup they propose.
If you want you can have a look at how I am invoking it, in a svelte project here

For this bug I have less time to dedicate unfortunately, but once you have a fix, let me know, and I'll gladly test it.

You are right. I just didn't have time to read more of your code and to find out why it is reaching such condition. And for the reproducible test, I cannot easily give you something as it is not from my code. As I said, there is a CodeMirror inside this [plugin of milkdown](https://github.com/enpitsuLin/milkdown-lab/tree/master/packages/plugin-split-editing) and the error comes when I am using it, with the default setup they propose. If you want you can have a look at how I am invoking it, in a svelte project [here](https://github.com/nextgraph-org/nextgraph-rs/blob/master/ng-app/src/apps/MilkDownEditor.svelte) For this bug I have less time to dedicate unfortunately, but once you have a fix, let me know, and I'll gladly test it.
nikoPLP commented 2024-08-06 13:02:50 +02:00 (Migrated from github.com)

I can just add that with the proposed fix, CodeMirror seems to be happy and everything works fine.

I can just add that with the proposed fix, CodeMirror seems to be happy and everything works fine.
marijnh commented 2024-08-06 14:27:49 +02:00 (Migrated from github.com)

The problem is this code passing something that's not an actual StyleModule instance to EditorView.styleModule.of.

The problem is [this code](https://github.com/enpitsuLin/milkdown-lab/blob/master/packages/plugin-split-editing/src/codemirror.ts#L75) passing something that's not an actual `StyleModule` instance to `EditorView.styleModule.of`.
nikoPLP commented 2024-08-06 14:31:37 +02:00 (Migrated from github.com)

Yes, I have seen that code today and wondered if it was good or not.
I will talk with the developers of the plugin.
Thanks for looking into it!

Yes, I have seen that code today and wondered if it was good or not. I will talk with the developers of the plugin. Thanks for looking into it!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
marijn/style-mod!13
No description provided.