Skip to content

Commit 50c315a

Browse files
committed
feat(#41): hydration -> additional props with name different from attribute -> handle
1 parent c0217b8 commit 50c315a

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/Halogen/VDom/DOM/Prop/Implementation.purs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ deleteRequiredElement = EFn.mkEffectFn2 \element extraAttributeNames -> do
3434
EFn.runEffectFn2 Util.warnAny "Error info: " { element, extraAttributeNames }
3535
throwException $ error $ "Cannot delete element " <> quote element <> " that is not present in extraAttributeNames (check warning above for more information)"
3636

37+
checkPropExistsAndIsEqualAndDelete :: EFn.EffectFn5 (Set.Set String) String PropValue DOM.Element String Unit
38+
checkPropExistsAndIsEqualAndDelete = EFn.mkEffectFn5 \extraAttributeNames propName val el correspondingAttributeName -> do
39+
checkPropExistsAndIsEqual propName val el
40+
EFn.runEffectFn2 deleteRequiredElement correspondingAttributeName extraAttributeNames
41+
3742
hydrateApplyProp
3843
a
3944
. Fn.Fn4
@@ -51,24 +56,24 @@ hydrateApplyProp = Fn.mkFn4 \extraAttributeNames el emit events → EFn.mkEffect
5156
pure v
5257
Property propName val → do
5358
case propName of
54-
"className" -> do
55-
checkPropExistsAndIsEqual propName val el
56-
EFn.runEffectFn2 deleteRequiredElement "class" extraAttributeNames
59+
-- | We use custom check for "href" (i.e. checking attribute instead of property) because:
60+
-- | with <a href="/foo"></a>
61+
-- | property $0.href is eq to "http://localhost:3000/foo"
62+
-- | but attribute
63+
-- | $0.attributes.href.value is eq to "/foo"
64+
-- | $0.getAttribute("href") is eq to "/foo" too
65+
-- |
66+
-- | The same is true for <link> elements also
5767
"href" -> do
58-
-- | We use custom check (i.e. checking attribute instead of property) because:
59-
-- | with <a href="/foo"></a>
60-
-- | property $0.href is eq to "http://localhost:3000/foo"
61-
-- | but attribute
62-
-- | $0.attributes.href.value is eq to "/foo"
63-
-- | $0.getAttribute("href") is eq to "/foo" too
64-
-- |
65-
-- | The same is true for <link> elements also
66-
6768
checkAttributeExistsAndIsEqual Nothing "href" (anyToString val) el
6869
EFn.runEffectFn2 deleteRequiredElement "href" extraAttributeNames
70+
-- | these 4 property names are taken from https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.server.js#L196-L201
71+
"className" -> EFn.runEffectFn5 checkPropExistsAndIsEqualAndDelete extraAttributeNames propName val el "class"
72+
"htmlFor" -> EFn.runEffectFn5 checkPropExistsAndIsEqualAndDelete extraAttributeNames propName val el "for"
73+
"httpEquiv" -> EFn.runEffectFn5 checkPropExistsAndIsEqualAndDelete extraAttributeNames propName val el "http-equiv"
74+
"acceptCharset" -> EFn.runEffectFn5 checkPropExistsAndIsEqualAndDelete extraAttributeNames propName val el "accept-charset"
6975
_ -> do
7076
checkPropExistsAndIsEqual propName val el
71-
let fullAttributeName' = toLower propName -- transforms `colSpan` to `colspan`
7277
case typeOf (unsafeToForeign val), (unsafeCoerce :: PropValue -> Boolean) val of
7378
-- | If this is a boolean and is false - then it should not have been prerendered
7479
-- |
@@ -83,7 +88,9 @@ hydrateApplyProp = Fn.mkFn4 \extraAttributeNames el emit events → EFn.mkEffect
8388
-- | `<button disabled=""></button>` the `$0.disabled === true`
8489
-- | `<button></button>` the `$0.disabled === false`
8590
"boolean", false -> pure unit
86-
_, _ -> EFn.runEffectFn2 deleteRequiredElement fullAttributeName' extraAttributeNames
91+
_, _ ->
92+
let fullAttributeName' = toLower propName -- transforms `colSpan` to `colspan`
93+
in EFn.runEffectFn2 deleteRequiredElement fullAttributeName' extraAttributeNames
8794

8895
pure v
8996
Handler eventType emitterInputBuilder → do

0 commit comments

Comments
 (0)