Skip to content

Commit 4dcc4f3

Browse files
committed
[#247] Experimental: allow elision of js/require forms
1 parent 4dc2230 commit 4dcc4f3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/taoensso/sente.cljc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,14 @@
877877

878878
:handled)))
879879

880+
(defmacro ^:private elide-require
881+
"Experimental. The presence of `js/require` calls can cause issues with
882+
React Native, even if they never execute. Currently no other known
883+
workarounds. Ref. https://github.com/ptaoussanis/sente/issues/247."
884+
[& body]
885+
(when-not (enc/get-sys-val "SENTE_ELIDE_JS_REQUIRE")
886+
`(do ~@body)))
887+
880888
#?(:cljs
881889
(def ^:private ?node-npm-websocket_
882890
"nnil iff the websocket npm library[1] is available.
@@ -887,13 +895,14 @@
887895
[1] Ref. https://www.npmjs.com/package/websocket
888896
[2] Ref. https://github.com/RyanMcG/lein-npm"
889897
(delay ; Eager eval causes issues with React Native, Ref. #247,
890-
(when (and node-target? (exists? js/require))
891-
(try
892-
(js/require "websocket")
893-
;; In particular, catch 'UnableToResolveError'
894-
(catch :default e
895-
;; (errorf e "Unable to load npm websocket lib")
896-
nil))))))
898+
(elide-require
899+
(when (and node-target? (exists? js/require))
900+
(try
901+
(js/require "websocket")
902+
;; In particular, catch 'UnableToResolveError'
903+
(catch :default e
904+
;; (errorf e "Unable to load npm websocket lib")
905+
nil)))))))
897906

898907
#?(:cljs
899908
(defrecord ChWebSocket

0 commit comments

Comments
 (0)