Skip to content

Commit

Permalink
feat!: change mutation_detection and allow_reactive_boolean defaults
Browse files Browse the repository at this point in the history
BREAKING CHANGE: an error is now raised if a reactive variable (not its value) is used in boolean comparisons
BREAKIGN CHANGE: mutation detection is now enabled by default
  • Loading branch information
iisakkirotko committed Dec 23, 2024
1 parent e1ae701 commit 66aec27
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 1 addition & 2 deletions solara/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,4 @@
logger = logging.getLogger("solara.components")
logger.warning(f"Default container {main.default_container} not found in solara.components. Defaulting to Column.")

# TODO: When Solara 2.0 releases Column should be replaced with Fragment
reacton.core._default_container = _container or Column # noqa: F405
reacton.core._default_container = _container or Fragment # noqa: F405
5 changes: 2 additions & 3 deletions solara/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ class Config:

class MainSettings(BaseSettings):
check_hooks: str = "warn"
allow_reactive_boolean: bool = True
# TODO: also change default_container in solara/components/__init__.py
default_container: Optional[str] = "Column"
allow_reactive_boolean: bool = False
default_container: Optional[str] = "Fragment"

class Config:
env_prefix = "solara_"
Expand Down
13 changes: 9 additions & 4 deletions solara/toestand.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import solara
import solara.settings
import solara.server.settings
from solara import _using_solara_server

T = TypeVar("T")
Expand Down Expand Up @@ -355,7 +356,9 @@ def __init__(self, default_value: S, key=None, equals: Callable[[Any, Any], bool
self.default_value = default_value
self._unwrap = unwrap
self.equals = equals
self._mutation_detection = solara.settings.storage.mutation_detection
self._mutation_detection = solara.settings.storage.mutation_detection is True or (
solara.settings.storage.mutation_detection is None and not solara.server.settings.main.mode == "production"
)
if self._mutation_detection:
frame = _find_outside_solara_frame()
if frame is not None:
Expand Down Expand Up @@ -452,9 +455,11 @@ def mutation_detection_storage(default_value: S, key=None, equals=None) -> Value


def default_storage(default_value: S, key=None, equals=None) -> ValueBase[S]:
# in solara v2 we will also do this when mutation_detection is None
# and we do not run on production mode
if solara.settings.storage.mutation_detection is True:
# We use mutation detection if it is explicitly enabled, or if it is not explicitly disabled and
# We aren't running in production mode
if solara.settings.storage.mutation_detection is True or (
solara.settings.storage.mutation_detection is None and not solara.server.settings.main.mode == "production"
):
return mutation_detection_storage(default_value, key=key, equals=equals)
else:
return KernelStoreValue[S](default_value, key=key, equals=equals or equals_extra)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/toestand_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,13 @@ def Test():

box, rc = solara.render(Test(), handle_error=False)

if solara.settings.storage.mutation_detection:
if solara.settings.storage.mutation_detection is not False:
# a copy is made, so get a reference to the actual used object
df = get_storage(store).value.public
assert rc.find(v.Alert).widget.children[0] == repr(id(df))
df2 = df2.copy()
store.set(df2)
if solara.settings.storage.mutation_detection:
if solara.settings.storage.mutation_detection is not False:
df2 = get_storage(store).value.public
assert rc.find(v.Alert).widget.children[0] == repr(id(df2))

Expand Down

0 comments on commit 66aec27

Please sign in to comment.