Skip to content

Fix: HTML nodes being silently dropped in View's Monad instance#196

Open
jkasalt wants to merge 1 commit intoseanhess:mainfrom
jkasalt:fix/view-monad-impl
Open

Fix: HTML nodes being silently dropped in View's Monad instance#196
jkasalt wants to merge 1 commit intoseanhess:mainfrom
jkasalt:fix/view-monad-impl

Conversation

@jkasalt
Copy link

@jkasalt jkasalt commented Mar 20, 2026

Hello,

When using >>= directly, or when ApplicativeDo is enabled (which introduces a join call that goes through >>=), all but the last element in a do block would be silently dropped from the rendered HTML.

For example:

{-# LANGUAGE ApplicativeDo #-}
col $ do
  el "One"
  el "Two"
  el "Three"

or

col $ el "One" >>= \_ -> el "Two" >>= \_ -> el "Three"

would render only "Three".

Cause

The >>= implementation of View was extracting only the return value from the first action via (.value) <$> ea, discarding its Html nodes entirely:

View ea >>= famb = View $ do
  a <- (.value) <$> ea   -- nodes from ea are thrown away
  let View eb = famb a
  eb

Fix

Run the first action fully to obtain its Html value, then delegate node accumulation to Html's own >>, which correctly concatenates both node lists:

View ea >>= famb = View $ do
  ha <- ea
  let View eb = famb ha.value
  (ha >>) <$> eb

Notes

The bug was not visible when using plain do notation without ApplicativeDo, because GHC desugars it to >> which is defined as (*>) and bypasses >>= entirely. The bug only manifests when >>= is called directly or through join.

Previously `>>=` was extracting only the return value of the `Html` from
the first action, discarding its nodes entierly.

This caused all but the last node to be silently dropped when `>>=` was
used manually or when the `ApplicativeDo` language extension introduced
a `join` call (which uses `>>=` under the hood).

The fix runs the first action to obtain its `Html` value, then delegates
node accumulation to `Html`'s own `>>`, which correctly concatenates
both node lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant