cherry-markdown icon indicating copy to clipboard operation
cherry-markdown copied to clipboard

[Bug report]关于setMarkdown、setValue插入文本后出现Uncaught TypeError: Cannot read properties of undefined (reading 'chunkSize')错误问题

Open stonexwx opened this issue 2 years ago • 9 comments

Describe the bug 我试图使用Tauri读取外部md文件赋值到cherry里面,其他md文件都可以正常使用,唯独一下Markdown文本会引起这个bug

To Reproduce

# Java常见面试题

## JDK\JRE\JVM有什么区别

◆JDK: Java Development Kit 针对Java程序员的产品
◆JRE: Java Runtime Environment是运行Java的环境集合
◆JVM: Java虚拟机用于运行Java字节码文件,跨平台的核心

## 常用数字类型的区别

|       名称       | 取值范围         | 存储空间 |
| :--------------: | ---------------- | -------- |
|   字节(byte)   | -2^7~2^7-1       | 1        |
| 短整数(short)  | -2^15~2^15-1     | 2        |
|   整数(int)    | -2^31~2^31-1     | 4        |
|  长整数(long)  | -2^63~2^63-1     | 8        |
| 单精度(float)  | 2^-149~2^128-1   | 4        |
| 双精度(double) | 2^-1074~2^1024-1 | 8        |

## Float在JVM中的保存形式

float在JVM中保存方式为小数点后七位的科学计数方式

```java
float d1 = 432423423f;
float d2 = d1+1;
if(d1==d2){
    sout()
}else{
    sout()
}
```
输出相等

原因是对于单精度浮点型在内存中以科学计数法保存,即4.3242342E7 加个1和不加一样

银行使用*BigDecimal*

## 随机数的使用

> 随机生成30~100之间的数

```java
int min = 30;
int max =100;
new Random().nextInt(max-min)+min;
```

```java
int min = 30;
int max =100;
(int)(Math.random()*(max-min))+min
```

## 面向对象的三大特征

1. 封装
2. 继承
3. 多态

## 静态变量和实例变量的区别

+ 语法区别:静态变量前要加static关键字,实例则不用
+ 隶属区别:实例变量属于某个对象的属性,而静态属于类
+ 运行区别:静态变量在JVM加载类自己码创建,实例变量在实例化对象时创建

静态变量不会被gc垃圾回收

静态变量存储在jvm方法区中,实例变量存储在对象堆中

## 类的加载顺序

1. 静态优先
2. 父类优先
3. 非静态块优于构造函数

当成功插入后,在文本末尾敲击回车会导致编辑区出现异常,如图所示 image 控制台报错 image

cherry-markdown.esm.js:1 
        
       Uncaught TypeError: Cannot read properties of undefined (reading 'chunkSize')
    at Vt2 (cherry-markdown.esm.js:1:54476)
    at qe2 (cherry-markdown.esm.js:1:67189)
    at un2 (cherry-markdown.esm.js:1:72560)
    at gn2 (cherry-markdown.esm.js:1:74888)
    at cherry-markdown.esm.js:1:109369
    at ai2 (cherry-markdown.esm.js:1:109425)
    at Wr2 (cherry-markdown.esm.js:1:102413)
    at cherry-markdown.esm.js:1:101595
    at cherry-markdown.esm.js:1:101711
    at cherry-markdown.esm.js:1:101435

但他依然可以输入,但是没有光标啥都看不到。 我尝试了setValue、setMarkdown、insert都无法解决这个问题。 直接复制到编辑区是没有任何问题的 image

Environment (please complete the following information):

  • OS: [e.g. Windows]
  • Browser [e.g. WebView2]
  • Version [e.g. 0.8.9]

stonexwx avatar Jan 12 '23 15:01 stonexwx

https://user-images.githubusercontent.com/59043142/212118814-a0b593eb-d9b7-4b7a-a6d9-1c7d97b08682.mp4

stonexwx avatar Jan 12 '23 16:01 stonexwx

这个有可能是文件编码格式导致的报错,建议在读文件的时候强制将编码格式设置成当前网页的编码格式~

sunsonliu avatar Jan 13 '23 01:01 sunsonliu

因为rust读取的文件都是UTF-8的编码,我能确保每个文件编码是一致的

stonexwx avatar Jan 13 '23 03:01 stonexwx

https://github.com/codemirror/codemirror5/issues/4135 可能是我们计算行号的逻辑有问题,我们尝试定位下

sunsonliu avatar Jan 13 '23 06:01 sunsonliu

好的 我尝试使用 engine.makeHtml(markdown:string) 将上述markdown转换为html 在使用 engine.makeMarkdown(html:string) 转换回来,依旧会出现上述错误 目前其他文档都可以正常打开,不知道这个文档有啥魔力

stonexwx avatar Jan 13 '23 08:01 stonexwx

破案了,new Cherry返回的对象不能被代理,vue3的ref会导致Cherry的方法产生奇奇怪怪的bug

stonexwx avatar Jan 22 '23 01:01 stonexwx

破案了,new Cherry返回的对象不能被代理,vue3的ref会导致Cherry的方法产生奇奇怪怪的bug

兄弟,我也遇到了同样的问题,按照你的方式避免使用ref代理cherry实例,然后就正常了,我想请问下你是怎么定位到这个问题的?非常感谢

xdewx avatar Mar 04 '23 08:03 xdewx

兄弟,我也遇到了同样的问题,按照你的方式避免使用ref代理cherry实例,然后就正常了,我想请问下你是怎么定位到这个问题的?非常感谢

因为官方给的那个在线api测试的地方并不会触发我遇到的bug,然后我就使用未代理过的cherry实例尝试复现,结果都是正常的,于是我就在想是不是vue的ref的问题,然后就用代理试了一下果然又不行了。于是乎我创建了一个单例模式的cherry对象为全局服务

stonexwx avatar Mar 06 '23 05:03 stonexwx

ref代理过后,后端传过来的markdown字符串一复写进编辑器,光标就到处乱跑,还好有人遇到类似的问题,总算解决了

chengjiang-09 avatar Aug 04 '23 06:08 chengjiang-09