Skip to content

Commit

Permalink
Fix uniqDynPure crashing after being reconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
zyla committed Oct 8, 2024
1 parent 44c06fa commit 6460edb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Specular/Internal/Incremental.purs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@ connect = mkEffectFn1 \node -> do
pure unit

value <- runEffectFn1 source.compute node
runEffectFn2 Node.set_value node value

-- Note: `compute` can return `none`, which means "do not update the value",
-- in cases where we're re-connecting a node which was previously alive.
-- In that case, don't erase the previous value.
if Optional.isSome value then
runEffectFn2 Node.set_value node value
else
pure unit

runEffectFn1 Profiling.end mark

Expand Down
16 changes: 16 additions & 0 deletions test/node/DynamicSpec.purs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ spec = describe "Dynamic" $ do
-- clean up
liftEffect unsub1

it "works after disconnecting and reconnecting" $ withLeakCheck do
log <- liftEffect $ new []
root <- Ref.new 1
let dyn = uniqDynPure (Ref.value root)
unsub1 <- liftEffect $ execCleanupT do
subscribeEvent_ (append log) (changed dyn)
liftEffect unsub1

unsub2 <- liftEffect $ execCleanupT do
subscribeEvent_ (append log) (changed dyn)

readDynamic dyn `shouldReturn` 1

-- clean up
liftEffect unsub2

describe "foldDynMaybe" $ do
it "triggers only when function returns Just" $ withLeakCheck $ do
{ event, fire } <- liftEffect newEvent
Expand Down

0 comments on commit 6460edb

Please sign in to comment.