From e835e36b8e8e85efad2f4be936d50c6373960ef7 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Sat, 15 May 2021 02:30:03 -0400 Subject: [PATCH] Fix glitchy group editing Currently, when groups are edited, the new groups flicker, but the UI soon reverts to the old groups. This is because the returned API response has the old group values. This, in turn, is because we eager load groups, and when we sync the new group relation, that doesn't update the groups saved in memory. By unsetting the relation, we make sure the right groups are returned (and also available to the GroupsChanged event). See https://github.com/flarum/core/issues/2514 --- framework/core/src/User/Command/EditUserHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/src/User/Command/EditUserHandler.php b/framework/core/src/User/Command/EditUserHandler.php index cdf183e51..51cdd6264 100644 --- a/framework/core/src/User/Command/EditUserHandler.php +++ b/framework/core/src/User/Command/EditUserHandler.php @@ -130,6 +130,7 @@ class EditUserHandler $user->afterSave(function (User $user) use ($newGroupIds) { $user->groups()->sync($newGroupIds); + $user->unsetRelation('groups'); }); }