修复"我在本群的昵称"保存时硬编码 version:0,与本文件其余乐观锁写法不一致
现象:GET /groups/{topic}/members/me/profile 实测确认真实带 version 字段(非空),
但 MyNicknameEditor 保存时一直硬编码 updateMyGroupProfile(topic, value, 0),从不使用
这个已经到手的真实版本号。
根因/影响:跟本文件其余"编辑单个字段+乐观锁"写法(GroupNameEditor/
GroupDescriptionEditor 用 getGroup 拿到的真实 version;Governance/OwnerSelect 的
注释更明确写过"version<=0 时服务端会整个跳过乐观锁 WHERE 子句,两次几乎同时的写入会
静默覆盖,没有冲突信号")不一致。实测验证这里同样如此:真实 version 是 1,PUT 时传 0
依然 200 成功,服务端自己把 version 推到了 2——多标签页/多端几乎同时修改自己在本群的
昵称时,后写入的会静默覆盖先写入的。
修复:GET 到的 version 存进 state,保存时原样带上,不再硬编码 0。
验证:真实浏览器操作,改群昵称两次,第二次 PUT 请求前 GET 到的 version 正确是上一次
保存后服务端返回的版本号(1→2→3 依次递增),不再是硬编码的 0。
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
8cb96e9254
commit
53e28e3bc6
@@ -1199,12 +1199,21 @@ function MyNicknameEditor({topic, onToast}) {
|
||||
const [value, setValue] = React.useState('');
|
||||
// getGroupMembers' list items never include group_nickname (confirmed live) -- only
|
||||
// GET .../members/me/profile actually returns it, same fix as GroupProfile's preview row above.
|
||||
// 同一个 GET 实测确认真的带 version 字段(不是空字符串/undefined),但这里原来保存时
|
||||
// 一直硬编码 version:0——跟本文件其余"编辑单个字段+乐观锁"的写法(GroupNameEditor/
|
||||
// GroupDescriptionEditor 用 getGroup 拿到的真实 version,Governance/OwnerSelect 的
|
||||
// 注释更是明确写了"version<=0 时服务端会整个跳过乐观锁 WHERE 子句,两次并发写入会
|
||||
// 静默覆盖")不一致。实测验证过这里同样如此:明明真实 version 是 1,PUT 时传 0 依然
|
||||
// 200 成功且服务端自己把 version 推到了 2——多标签页/多端几乎同时改自己在本群的昵称
|
||||
// 时,后写入的会静默覆盖先写入的,没有任何冲突信号。跟其余几处一样,把已经拿到手的
|
||||
// 真实 version 存下来,保存时原样带上。
|
||||
const [version, setVersion] = React.useState(0);
|
||||
React.useEffect(() => {
|
||||
if (!topic) return;
|
||||
getMyGroupProfile(topic).then(data => setValue(data.nickname || '')).catch(() => {});
|
||||
getMyGroupProfile(topic).then(data => { setValue(data.nickname || ''); setVersion(data.version || 0); }).catch(() => {});
|
||||
}, [topic]);
|
||||
const save = () => {
|
||||
updateMyGroupProfile(topic, value.trim(), 0).then(() => {
|
||||
updateMyGroupProfile(topic, value.trim(), version).then(() => {
|
||||
onToast('保存成功'); window.setTimeout(() => navigate('group-settings', topic), 600);
|
||||
}).catch(err => onToast(err.message || '保存失败'));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user