From 60f7b4bc0c27672459a7a9babf22be2465258e4f Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Fri, 4 May 2018 18:47:45 +0300 Subject: [PATCH] Remove :> component type assertion Component could be plain JS object with some private React properties, and it is not easy to check for this. Instead just allow all value for :> but check that React will throw error from createElement. Fixes #369 --- src/reagent/impl/template.cljs | 2 -- test/reagenttest/testreagent.cljs | 16 +++++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index f75472c..c20e130 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -387,8 +387,6 @@ 0 (let [comp (nth v 1 nil)] ;; Support [:> comp ...] (assert (= ">" n) (hiccup-err v "Invalid Hiccup tag")) - (assert (or (string? comp) (fn? comp)) - (hiccup-err v "Expected React component in")) (native-element #js{:name comp} v 2)) ;; Support extended hiccup syntax, i.e :div.bar>a.foo ;; Apply metadata (e.g. :key) to the outermost element. diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index 595fbca..204d8c6 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -962,9 +962,17 @@ (is (thrown-with-msg? :default #"Invalid Hiccup form: \[23]" (rstr [23]))) - (is (thrown-with-msg? - :default #"Expected React component in: \[:> \[:div]]" - (rstr [:> [:div]]))) + ;; This used to be asserted by Reagent, but because it is hard to validate + ;; components, now we just trust React will validate elements. + ; (is (thrown-with-msg? + ; :default #"Expected React component in: \[:> \[:div]]" + ; (rstr [:> [:div]]))) + ;; This is from React.createElement + (debug/track-warnings + (wrap-capture-console-error + #(is (thrown-with-msg? + :default #"Element type is invalid:" + (rstr [:> [:div]]))))) (is (thrown-with-msg? :default #"Invalid tag: 'p.'" (rstr [:p.]))) @@ -1213,8 +1221,6 @@ (fn [v] (r/as-element [:div "Context: " v]))]]))))) - ;; FIXME: :> assertion broken - #_ (testing "context works with :>" (is (= "
Context: bar
" (rstr [:> Provider {:value "bar"}