diff --git a/ghc-src/Miso/Html/Internal.hs b/ghc-src/Miso/Html/Internal.hs
index f69ceba9..394a3adf 100644
--- a/ghc-src/Miso/Html/Internal.hs
+++ b/ghc-src/Miso/Html/Internal.hs
@@ -51,7 +51,6 @@ module Miso.Html.Internal (
import Data.Aeson (Value(..), ToJSON(..))
import qualified Data.Map as M
-import Data.Monoid
import Data.Proxy
import Data.String (IsString(..))
import qualified Data.Text as T
diff --git a/ghcjs-ffi/Miso/FFI.hs b/ghcjs-ffi/Miso/FFI.hs
index 4bb300dc..5ef5b798 100644
--- a/ghcjs-ffi/Miso/FFI.hs
+++ b/ghcjs-ffi/Miso/FFI.hs
@@ -95,8 +95,13 @@ syncPoint = pure ()
-- | Set property on object
set :: ToJSVal v => JSString -> v -> OI.Object -> IO ()
+set "class" v obj = toJSVal v >>= appendClass obj
set k v obj = toJSVal v >>= \x -> OI.setProp k x obj
+-- | Only used for 'class', guaranteed to be a MisoString
+foreign import javascript unsafe "if ('class' in $1) { $1['class'] += ' ' + $2; } else { $1['class'] = $2; }"
+ appendClass :: OI.Object -> JSVal -> IO ()
+
foreign import javascript unsafe "$1.addEventListener($2, $3);"
addEventListener' :: JSVal -> JSString -> Callback (JSVal -> IO ()) -> IO ()
diff --git a/jsaddle-ffi/Miso/FFI.hs b/jsaddle-ffi/Miso/FFI.hs
index 76869975..8d4242e1 100644
--- a/jsaddle-ffi/Miso/FFI.hs
+++ b/jsaddle-ffi/Miso/FFI.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE LambdaCase #-}
-----------------------------------------------------------------------------
-- |
@@ -80,6 +81,17 @@ objectToJSVal = toJSVal
-- | Set property on object
set :: ToJSVal v => JSString -> v -> OI.Object -> JSM ()
+set (unpack -> "class") v obj = do
+ classSet <- ((pack "class") `elem`) <$> listProps obj
+ if classSet
+ then do
+ classStr <- fromJSValUnchecked =<< getProp (pack "class") obj
+ vStr <- fromJSValUnchecked =<< toJSVal v
+ v' <- toJSVal (classStr <> pack " " <> vStr)
+ setProp (pack "class") v' obj
+ else do
+ v' <- toJSVal v
+ setProp (pack "class") v' obj
set k v obj = do
v' <- toJSVal v
setProp k v' obj
diff --git a/jsbits/isomorphic.js b/jsbits/isomorphic.js
index 59982c86..f3d1c84d 100644
--- a/jsbits/isomorphic.js
+++ b/jsbits/isomorphic.js
@@ -25,10 +25,14 @@ window['copyDOMIntoVTree'] = function copyDOMIntoVTree(logLevel,mountPoint, vtre
} else if (mountPoint.childNodes.length === 0) {
node = mountPoint.appendChild (doc.createElement('div'));
} else {
- while (mountPoint.childNodes[mountChildIdx].localName === 'script' || mountPoint.childNodes[mountChildIdx].nodeType === Node.TEXT_NODE){
+ while (mountPoint.childNodes[mountChildIdx] && (mountPoint.childNodes[mountChildIdx].nodeType === Node.TEXT_NODE || mountPoint.childNodes[mountChildIdx].localName === 'script')){
mountChildIdx++;
}
- node = mountPoint.childNodes[mountChildIdx];
+ if (!mountPoint.childNodes[mountChildIdx]) {
+ node = doc.body.appendChild (doc.createElement('div'));
+ } else {
+ node = mountPoint.childNodes[mountChildIdx];
+ }
}
if (!window['walk'](logLevel,vtree, node, doc)) {