This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-29
Channels
- # announcements (9)
- # aws (1)
- # beginners (133)
- # boot (2)
- # calva (94)
- # cider (48)
- # cljdoc (7)
- # cljsrn (22)
- # clojure (128)
- # clojure-europe (22)
- # clojure-finland (7)
- # clojure-greece (6)
- # clojure-losangeles (3)
- # clojure-nl (81)
- # clojure-spec (30)
- # clojure-uk (60)
- # clojure-ukraine (1)
- # clojurescript (45)
- # core-async (26)
- # cursive (18)
- # datomic (12)
- # defnpodcast (1)
- # duct (4)
- # editors (4)
- # emacs (6)
- # fulcro (37)
- # graphql (4)
- # jobs (2)
- # jobs-rus (1)
- # juxt (7)
- # kaocha (2)
- # leiningen (1)
- # nrepl (22)
- # off-topic (2)
- # re-frame (16)
- # reagent (8)
- # reitit (22)
- # ring-swagger (5)
- # shadow-cljs (81)
- # tools-deps (4)
I need to (conditionally?) import a polyfill to support a JS library (react-boostrap, sigh, doesn’t work on IE11). Needs Object.assign. Is there a recommended way to do this with shadow-cljs/clojurescript? Should I load it conditionally directly in the HTML?
There’s more to this — I actually need to make sure to load some polyfills before any 3rd-party code is loaded. I’m using for now a http://polyfill.io script element, but I would prefer if the contents of the returned polyfill to be prepended to my final bundled file, but without passing through google closure optimizations at all.
@orestis you can set :compiler-options {:language-out :ecmascript3}
and it should add the closure polyfill for that
I’m writing an issue about it since it seems to be more complicated than that (due to Closure polyfill and React weird interactions)
alternatively you can set :compiler-options {:closure-injected-libs #{"util/assign"}}
note that this only really applies to release
builds so if you are testing with development builds that may not work
but since its fairly common for JS libs to unconditionally ship their own polyfills you may end up with multiple versions and the same polyfill
Yeah that’s extremely annoying. I see for example that react-bootstrap depends on babel runtime…
I need it for development as well — our designers need to be able to test in IE11 while in dev mode to fix CSS and other things.
I would honestly recommend keeping the polyfills as a separate script element which you can make conditional for only IE
@orestis in the github issue please provide at least some source reference on how I would reproduce the problem
Made a minimal repro here: https://github.com/orestis/shadow-polyfill-issue
Thanks so much for taking some time to look into this. It’s not a high priority for me, so please don’t feel any pressure at all.
Doesn’t seem to fix the problem for the actual app… making sure I actually have the correct things.
There might be other things in my actual application that trigger this in other ways.
(ns
(:require
["react-bootstrap" :as bs]
))
(defn init []
(js/console.log js/Object js/Object.assign))
;; shadow-cljs configuration
{:source-paths
["src/dev"
"src/main"
"src/test"]
:dependencies
[]
:dev-http
{9005 "public"}
:builds
{:app {:target :browser
:modules {:main {:init-fn }}
:compiler-options
{:rewrite-polyfills true
:language-out :ecmascript3}
}}}
That’s true, in release mode the error happens during load. In dev mode it’s shadow catching the error and reporting it.
only interested in release
as that is currently the only thing that can potentially work
I’ll see about my minimal repro in release mode and report back after lunch. Thanks for looking into this!
@orestis it works if you set :js-options {:rewrite-polyfills true}
+ the :compiler-options
:js-options
{:rewrite-polyfills true}
:compiler-options
{:language-out :ecmascript3
:rewrite-polyfills true
:infer-externs :auto}
it worked in my test since I used Object.assign
in the CLJS sources which caused the polyfills to be added
but the JS sources are processed in a separate pass so it must be enabled there manually
Can confirm that the js-options fixes the Object.assign issue. The broken Symbol.for polyfill though seems to linger on, probably need to wait for a Google Closure compiler bump for this? Seems the issue is fixed upstream (or at least closed).
https://github.com/facebook/react/issues/13414 , traced to https://github.com/google/closure-compiler/issues/3052
For some reason, it’s 60107 wherever a react fragment appears. I haven’t been able to get any meaningful google hits for this so potentially you’ll get another number.
(defn ^:dev/after-load render []
(react-dom/render
(r/createElement r/Fragment nil
(r/createElement "div" nil "content 1")
(r/createElement "div" nil "content 2"))
(js/document.getElementById "main")))