Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against inner component null messages #1080

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Fabulous/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open System.Collections.Concurrent
// Runner is created for the component itself. No point in reusing a runner for another component

/// Create a new Runner handling the update loop for the component
type Runner<'arg, 'model, 'msg>(getState: unit -> 'model, setState: 'model -> unit, program: Program<'arg, 'model, 'msg>) =
type Runner<'arg, 'model, 'msg when 'msg: null>(getState: unit -> 'model, setState: 'model -> unit, program: Program<'arg, 'model, 'msg>) =
let mutable _activeSubs = Sub.Internal.empty
let mutable _reentering = false
let mutable _stopped = false
Expand All @@ -20,11 +20,14 @@ type Runner<'arg, 'model, 'msg>(getState: unit -> 'model, setState: 'model -> un
raise ex

let processMsgs dispatch msg =
let mutable lastMsg = ValueSome msg
// In cases where you have a Component() which itself is in a Component(program) and a side effect happens in the inner component, the outer component will dispatch a message that is null
// So here we need make sure that we don't process null messages `ValueSome null`
let mutable lastMsg = ValueOption.ofObj(msg)

while not _stopped && lastMsg.IsSome do
let model = getState()
let newModel, cmd = program.Update(lastMsg.Value, model)

let newModel, cmd = program.Update(unbox lastMsg.Value, model)
let subs = program.Subscribe(newModel)

setState newModel
Expand Down
Loading