Skip to content

Commit b1289ce

Browse files
committed
feat!: change mutation_detection and allow_reactive_boolean defaults
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
1 parent 26a76b0 commit b1289ce

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

solara/components/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,4 @@
7373
logger = logging.getLogger("solara.components")
7474
logger.warning(f"Default container {main.default_container} not found in solara.components. Defaulting to Column.")
7575

76-
# TODO: When Solara 2.0 releases Column should be replaced with Fragment
77-
reacton.core._default_container = _container or Column # noqa: F405
76+
reacton.core._default_container = _container or Fragment # noqa: F405

solara/settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ class Config:
5454

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

6160
class Config:
6261
env_prefix = "solara_"

solara/toestand.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import solara
3333
import solara.settings
34+
import solara.server.settings
3435
from solara import _using_solara_server
3536
from solara.util import nullcontext
3637

@@ -372,7 +373,9 @@ def __init__(self, default_value: S, key=None, equals: Callable[[Any, Any], bool
372373
self.default_value = default_value
373374
self._unwrap = unwrap
374375
self.equals = equals
375-
self._mutation_detection = solara.settings.storage.mutation_detection
376+
self._mutation_detection = solara.settings.storage.mutation_detection is True or (
377+
solara.settings.storage.mutation_detection is None and not solara.server.settings.main.mode == "production"
378+
)
376379
if self._mutation_detection:
377380
frame = _find_outside_solara_frame()
378381
if frame is not None:
@@ -469,9 +472,11 @@ def mutation_detection_storage(default_value: S, key=None, equals=None) -> Value
469472

470473

471474
def default_storage(default_value: S, key=None, equals=None) -> ValueBase[S]:
472-
# in solara v2 we will also do this when mutation_detection is None
473-
# and we do not run on production mode
474-
if solara.settings.storage.mutation_detection is True:
475+
# We use mutation detection if it is explicitly enabled, or if it is not explicitly disabled and
476+
# We aren't running in production mode
477+
if solara.settings.storage.mutation_detection is True or (
478+
solara.settings.storage.mutation_detection is None and not solara.server.settings.main.mode == "production"
479+
):
475480
return mutation_detection_storage(default_value, key=key, equals=equals)
476481
else:
477482
return KernelStoreValue[S](default_value, key=key, equals=equals or equals_extra)

tests/unit/toestand_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,13 @@ def Test():
852852

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

855-
if solara.settings.storage.mutation_detection:
855+
if solara.settings.storage.mutation_detection is not False:
856856
# a copy is made, so get a reference to the actual used object
857857
df = get_storage(store).value.public
858858
assert rc.find(v.Alert).widget.children[0] == repr(id(df))
859859
df2 = df2.copy()
860860
store.set(df2)
861-
if solara.settings.storage.mutation_detection:
861+
if solara.settings.storage.mutation_detection is not False:
862862
df2 = get_storage(store).value.public
863863
assert rc.find(v.Alert).widget.children[0] == repr(id(df2))
864864

0 commit comments

Comments
 (0)