Fixing Uncaught TypeError: Cannot read property 'autoReconnect' of null (and add deps.edn)#75
Fixing Uncaught TypeError: Cannot read property 'autoReconnect' of null (and add deps.edn)#75dupuchba wants to merge 2 commits intonrepl:masterfrom
Conversation
| ([auto-reconnect?] | ||
| (websocket-connection auto-reconnect? nil)) | ||
| ([auto-reconnect? next-reconnect-fn] | ||
| (goog.net.WebSocket. auto-reconnect? next-reconnect-fn))) |
There was a problem hiding this comment.
This is great and obviously would work but have you also considered the following?
(goog.net.WebSocket. (js-obj "autoReconnect" auto-reconnect?) next-reconnect-fn)|
I ran into the same error after upgrading some project dependencies for JDK 11 support, and the fix to WebSocket instantiation resolved the error for me. Looks like the other proposed fix should work as well, happy to test and roll another pull request for that if preferred. |
|
I'm not familiar with the codebase, so I'm down with whatever people feel is best. |
| (websocket-connection auto-reconnect? nil)) | ||
| ([auto-reconnect? next-reconnect-fn] | ||
| (goog.net.WebSocket. auto-reconnect? next-reconnect-fn))) | ||
| (goog.net.WebSocket. (or auto-reconnect? false) (or next-reconnect-fn false)))) |
There was a problem hiding this comment.
Seems to me those can be some let-bindings instead, as the code looks a bit weird as proposed.
There was a problem hiding this comment.
yep, and false doesn't seem to be valid according to https://google.github.io/closure-library/api/goog.net.WebSocket.Options.html
maybe
(goog.net.WebSocket. (clj->js
(cond-> {}
auto-reconnect? (assoc "autoReconnect" auto-reconnect?)
next-reconnect-fn (assoc "getNextReconnect" next-reconnect-fn))))
or, to make things clearer, using something like assoc-some from https://github.com/weavejester/medley/blob/1.3.0/src/medley/core.cljc#L38
When we are trying to instantiate and goog.net.WebSocket object, it breaks with nil/null option.
So I pass
falsewhen params are nil.I also added
deps.ednto make it simpler to use:gitwith a specific sha in deps.edn