diff --git a/panel/io/location.py b/panel/io/location.py index b084b0e92f..35761521a0 100644 --- a/panel/io/location.py +++ b/panel/io/location.py @@ -221,15 +221,20 @@ def unsync(self, parameterized: param.Parameterized, parameters: Optional[List[s ptype = type(parameterized) raise ValueError(f"Cannot unsync {ptype} object since it " "was never synced in the first place.") - synced = [] + synced, unsynced = [], [] for p, params, watcher, on_error in self._synced: - if parameterized is p: - parameterized.param.unwatch(watcher) - if parameters is not None: - new_params = {p: q for p, q in params.items() - if p not in parameters} - new_watcher = parameterized.param.watch(watcher.fn, list(new_params)) - synced.append((p, new_params, new_watcher, on_error)) - else: + if parameterized is not p: synced.append((p, params, watcher, on_error)) + continue + parameterized.param.unwatch(watcher) + if parameters is None: + unsynced.extend(list(params.values())) + else: + unsynced.extend([q for p, q in params.items() if p in parameters]) + new_params = {p: q for p, q in params.items() + if p not in parameters} + new_watcher = parameterized.param.watch(watcher.fn, list(new_params)) + synced.append((p, new_params, new_watcher, on_error)) self._synced = synced + query = {k: v for k, v in self.query_params.items() if k not in unsynced} + self.search = '?' + urlparse.urlencode(query) if query else '' diff --git a/panel/tests/io/test_location.py b/panel/tests/io/test_location.py index 8a10599ace..272c77d318 100644 --- a/panel/tests/io/test_location.py +++ b/panel/tests/io/test_location.py @@ -37,12 +37,14 @@ def test_location_sync_query_init(location): assert location.search == "?integer=1&string=abc" location.unsync(p) assert location._synced == [] + assert location.search == "" def test_location_unsync(location): p = SyncParameterized(integer=1, string='abc') location.sync(p) assert location.search == "?integer=1&string=abc" location.unsync(p) + assert location.search == "" location.update_query(integer=2, string='def') assert p.integer == 1 assert p.string == "abc" @@ -55,6 +57,7 @@ def test_location_unsync_partial(location): location.sync(p) assert location.search == "?integer=1&string=abc" location.unsync(p, ['string']) + assert location.search == "?integer=1" location.update_query(integer=2, string='def') assert p.integer == 2 assert p.string == "abc" @@ -75,6 +78,7 @@ def test_location_sync_query_init_rename(location): assert location.search == "?int=1&str=abc" location.unsync(p) assert location._synced == [] + assert location.search == "" def test_location_sync_query(location): p = SyncParameterized() @@ -83,6 +87,7 @@ def test_location_sync_query(location): assert location.search == "?integer=2" location.unsync(p) assert location._synced == [] + assert location.search == "" def test_location_sync_param_init(location): p = SyncParameterized() @@ -92,6 +97,7 @@ def test_location_sync_param_init(location): assert p.string == "abc" location.unsync(p) assert location._synced == [] + assert location.search == "" def test_location_sync_on_error(location): p = SyncParameterized(string='abc') @@ -103,6 +109,7 @@ def on_error(change): assert changes == [{'integer': 'a'}] location.unsync(p) assert location._synced == [] + assert location.search == "" def test_location_sync_param_init_partial(location): p = SyncParameterized() @@ -112,6 +119,7 @@ def test_location_sync_param_init_partial(location): assert p.string is None location.unsync(p) assert location._synced == [] + assert location.search == "?string=abc" def test_location_sync_param_init_rename(location): p = SyncParameterized() @@ -121,6 +129,7 @@ def test_location_sync_param_init_rename(location): assert p.string == 'abc' location.unsync(p) assert location._synced == [] + assert location.search == "" def test_location_sync_param_update(location): p = SyncParameterized() @@ -130,3 +139,4 @@ def test_location_sync_param_update(location): assert p.string == "abc" location.unsync(p) assert location._synced == [] + assert location.search == ""