Tencent / cherry-markdown

✨ A Markdown Editor
Other
3.54k stars 412 forks source link

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

Closed stonexwx closed 2 months ago

stonexwx commented 1 year ago

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之间的数

int min = 30;
int max =100;
new Random().nextInt(max-min)+min;
int min = 30;
int max =100;
(int)(Math.random()*(max-min))+min

面向对象的三大特征

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

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

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

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

类的加载顺序

  1. 静态优先
  2. 父类优先
  3. 非静态块优于构造函数
当成功插入后,在文本末尾敲击回车会导致编辑区出现异常,如图所示
![image](https://user-images.githubusercontent.com/59043142/212112724-6938c76a-5f7f-4a32-9306-c7cceb517483.png)
控制台报错
![image](https://user-images.githubusercontent.com/59043142/212113098-cfce043d-e117-4314-89ee-915ee89193f9.png)

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](https://user-images.githubusercontent.com/59043142/212113840-f18032df-8f56-448b-b94a-83c0f0980664.png)

**Environment (please complete the following information):**
 - OS: [e.g. Windows]
 - Browser [e.g. WebView2]
 - Version [e.g. 0.8.9]
stonexwx commented 1 year ago

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

sunsonliu commented 1 year ago

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

stonexwx commented 1 year ago

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

sunsonliu commented 1 year ago

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

stonexwx commented 1 year ago

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

stonexwx commented 1 year ago

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

xdewx commented 1 year ago

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

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

stonexwx commented 1 year ago

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

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

chengjiang-09 commented 1 year ago

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