yjs / y-webrtc

WebRTC Connector for Yjs
MIT License
458 stars 111 forks source link

TypeError: Assignment to constant variable #9

Closed callum-atwal closed 4 years ago

callum-atwal commented 4 years ago

I was building my Angular application for production use where I ran into this weird issue (after some research, it turns out it isn't uncommon for production builds to have, what appears to be, breaking differences for both React and Angular - I suspect the same may apply for other frameworks).

It complains about the _docUpdateHandler function saying it is assigning something to a constant variable.

https://github.com/yjs/y-webrtc/blob/97df715a6bfb9dc271a9fa66667c438099b388c3/src/y-webrtc.js#L355

The only const I could see defined was on line 355 so I changed this to a let and the issue went away. This seems odd since this encoder variable is only being passed through to those other preceding functions.

It might be something worth looking into. Since I'm submitting my work, I'm making these hacky edits - limited by time to investigate this any further but thought I'd raise the issue if there is one that I'm not seeing :D

dmonad commented 4 years ago

This is a very strange issue and thanks for reporting it. Module bundlers really do weird stuff sometimes.

I'm pretty certain that the types and variable declarations are correct. The only problematic use of const I could find was here: https://github.com/yjs/y-webrtc/blob/97df715a6bfb9dc271a9fa66667c438099b388c3/src/y-webrtc.js#L193 Even though it is bad style, it is correct JavaScript because the variables are scoped. Did you change the variable declarations there too? Because, I don't see any reason for a problem in line 355.

callum-atwal commented 4 years ago

Nope, I had only changed Line 355. I too was positive it was correct. Angular's build optimizer seemed to disagree :(

dmonad commented 4 years ago

I renamed the encoder variable. Can you try and see if this also fixes the problem? My linter complains when I change the declaration type, so I'm looking for other ways to fix this problem.

I just published y-webrtc@10.1.4, could you please update your dependency and check if this fixes the problem?

callum-atwal commented 4 years ago

So I've realised a few things since raising this issue. I've been using slightly older versions of your modules since I've got an Angular v7 app which doesn't support the latest TypeScript (which consequently I think recent versions of yjs require a certain version of TypeScript - I'll raise this in the yjs repo as a potential issue)

I forked the y-webrtc repo, and oddly, Angular no longer complains with the same code? Very odd stuff going on but it's probably something I have done rather than the y-webrtc module. I'll close this issue :D