Skip to content

Commit 6328ea7

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 132d7aa commit 6328ea7

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
@@ -32,6 +32,7 @@
3232

3333
import solara
3434
import solara.settings
35+
import solara.server.settings
3536
from solara import _using_solara_server
3637

3738
T = TypeVar("T")
@@ -355,7 +356,9 @@ def __init__(self, default_value: S, key=None, equals: Callable[[Any, Any], bool
355356
self.default_value = default_value
356357
self._unwrap = unwrap
357358
self.equals = equals
358-
self._mutation_detection = solara.settings.storage.mutation_detection
359+
self._mutation_detection = solara.settings.storage.mutation_detection is True or (
360+
solara.settings.storage.mutation_detection is None and not solara.server.settings.main.mode == "production"
361+
)
359362
if self._mutation_detection:
360363
frame = _find_outside_solara_frame()
361364
if frame is not None:
@@ -452,9 +455,11 @@ def mutation_detection_storage(default_value: S, key=None, equals=None) -> Value
452455

453456

454457
def default_storage(default_value: S, key=None, equals=None) -> ValueBase[S]:
455-
# in solara v2 we will also do this when mutation_detection is None
456-
# and we do not run on production mode
457-
if solara.settings.storage.mutation_detection is True:
458+
# We use mutation detection if it is explicitly enabled, or if it is not explicitly disabled and
459+
# We aren't running in production mode
460+
if solara.settings.storage.mutation_detection is True or (
461+
solara.settings.storage.mutation_detection is None and not solara.server.settings.main.mode == "production"
462+
):
458463
return mutation_detection_storage(default_value, key=key, equals=equals)
459464
else:
460465
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
@@ -759,13 +759,13 @@ def Test():
759759

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

762-
if solara.settings.storage.mutation_detection:
762+
if solara.settings.storage.mutation_detection is not False:
763763
# a copy is made, so get a reference to the actual used object
764764
df = get_storage(store).value.public
765765
assert rc.find(v.Alert).widget.children[0] == repr(id(df))
766766
df2 = df2.copy()
767767
store.set(df2)
768-
if solara.settings.storage.mutation_detection:
768+
if solara.settings.storage.mutation_detection is not False:
769769
df2 = get_storage(store).value.public
770770
assert rc.find(v.Alert).widget.children[0] == repr(id(df2))
771771

0 commit comments

Comments
 (0)