@@ -21,6 +21,7 @@ const ALWAYS_REGISTER_CHANNELS = RefValue(true)
2121const USE_MODEL_STORAGE = RefValue (true )
2222const PRECOMPILE = RefValue (false )
2323const FIXED_TYPES = Dict {Module, Vector{Symbol}} ()
24+ const SHARE_CHANNELS_ACROSS_WINDOWS = RefValue {Union{Bool, Nothing}} (nothing )
2425
2526import MacroTools
2627import Pkg. TOML
@@ -29,6 +30,17 @@ function use_model_storage()
2930 USE_MODEL_STORAGE[]
3031end
3132
33+ """
34+ Whether windows in the same session should reuse the same channel.
35+
36+ If set to `nothing`, the default follows `use_model_storage()`:
37+ - `true` => share channels across windows
38+ - `false` => keep channels isolated unless explicitly enabled
39+ """
40+ function share_channels_across_windows ():: Bool
41+ SHARE_CHANNELS_ACROSS_WINDOWS[] === nothing ? use_model_storage () : SHARE_CHANNELS_ACROSS_WINDOWS[]
42+ end
43+
3244"""
3345Disables the automatic storage and retrieval of the models in the session.
3446Useful for large models.
@@ -458,7 +470,9 @@ function channeldefault(::Type{M}) where M<:ReactiveModel
458470
459471 model_id = Symbol (Stipple. routename (M))
460472
461- # Look up channel from session - session persistence should work regardless of model storage
473+ # Default channel sharing follows the model storage policy, but may be overridden explicitly.
474+ share_channels_across_windows () || return nothing
475+
462476 if use_model_storage ()
463477 stored_model = Stipple. ModelStorage. Sessions. GenieSession. get (model_id, nothing )
464478 stored_model === nothing ? nothing : getchannel (stored_model)
@@ -597,12 +611,12 @@ function init(t::Type{M};
597611 channel === nothing && (channel = channelfactory ())
598612 setchannel (model, channel)
599613
600- # Store model or channel in session based on model storage setting
614+ # Store model or channel in session based on model storage setting and explicit cross-window sync override.
601615 if use_model_storage ()
602- # Store full model when model storage is enabled
616+ # Store full model when model storage is enabled.
603617 Stipple. ModelStorage. Sessions. store (model)
604- else
605- # When model storage is disabled, only store the channel for session persistence
618+ elseif SHARE_CHANNELS_ACROSS_WINDOWS[] === true
619+ # When model storage is disabled but cross-window sync is explicitly on, store only the channel.
606620 model_id = Symbol (Stipple. routename (M))
607621 channel_key = Symbol (string (model_id) * " _channel" )
608622 Stipple. ModelStorage. Sessions. GenieSession. set! (channel_key, channel)
0 commit comments