joelburget / react-haskell

React bindings for Haskell
MIT License
351 stars 26 forks source link

Only one element rendering at each level in the DOM #16

Closed johncant closed 9 years ago

johncant commented 9 years ago

Firstly, I think react-haskell is a really good idea, and I'm using it to build a web application even if I have to keep changing all my application code and getting out of various different manifestations of cabal hell.

Secondly, I think I've found a bug:

{-# LANGUAGE OverloadedStrings #-}

import Haste.Prim
import Haste.DOM
import React

data ApplicationState = ApplicationState {
    foo :: JSString
  }

transition :: JSString -> ApplicationState -> (ApplicationState, [AnimConfig JSString ()])
transition signal oldState = (oldState, [])

index :: ApplicationState -> React ApplicationState JSString () ()
index s = do
  h1_ "Render things"
  h1_ "Render moar things"

main = do
    mElem <- elemById "app"
    case mElem of
      Nothing -> putStrLn "not found"
      Just elem -> do
          render elem =<< createClass index transition (ApplicationState "") () []
          return ()

Only renders "Render things", but I would expect "Render things" then "Render moar things". In general, the only the first child of any element in the React declaration seems to be rendering.

johncant commented 9 years ago

Actually, we only see this effect at the top level in a ReactClass. This is not a bug, because React's Javascript render only seems to render 1 element at the top level.