fix(web): address lifecycle and execution review findings

This commit is contained in:
abaishu0730 committed 2026-10-19 13:09:18 +08:00
1 parent 5c7ce76f5d
commit 3037f7f7ac
6 files changed
+56 -19

No files matched your search

+3 -3
View File
@@ -7,10 +7,10 @@ window.PageLifecycle=(()=>{
function bind(){if(!host)return;for(const form of host.querySelectorAll('form')){
if(forms.has(form)||form.dataset.lifecycle==='custom'||form.id==='assistant-compose'||!form.onsubmit||!form.querySelector('button[type="submit"]'))continue;
const state={baseline:snapshot(form),busy:false,failed:false,sensitive:/password|^user-form$/.test(form.id)||!!form.querySelector('input[type="password"]')||form.matches('[data-rule-resend],[data-rule-resolve],[data-rule-recheck],[data-execution-retry],#execution-scan,#exception-action,#storage-archive-form,#storage-folder-form'),save:null};forms.set(form,state);const original=form.onsubmit;
form.onsubmit=async event=>{event.preventDefault();if(state.busy)return;state.busy=true;state.failed=false;state.committed=false;form.setAttribute('aria-busy','true');const previous=activeSubmission;activeSubmission=state;
try{await original.call(form,event);if(!state.failed&&state.committed)state.baseline=snapshot(form);}catch(error){state.failed=true;window.dispatchEvent(new CustomEvent('page-operation-error',{detail:error}));}finally{state.busy=false;form.removeAttribute('aria-busy');activeSubmission=previous;}
form.onsubmit=async event=>{event.preventDefault();if(state.busy)return;state.busy=true;state.failed=false;state.committed=false;state.submitted=snapshot(form);form.setAttribute('aria-busy','true');const previous=activeSubmission;activeSubmission=state;
const locked=[...form.querySelectorAll('input,select,textarea')].filter(field=>!field.disabled);let restore=false;try{const work=original.call(form,event);if(form.id!=='schedule-form'&&work&&typeof work.then==='function'){restore=true;for(const field of locked)field.disabled=true;}await work;}catch(error){state.failed=true;window.dispatchEvent(new CustomEvent('page-operation-error',{detail:error}));}finally{if(restore&&form.isConnected)for(const field of locked)field.disabled=false;if(!state.failed&&state.committed)state.baseline=state.sensitive?snapshot(form):state.submitted;state.busy=false;form.removeAttribute('aria-busy');activeSubmission=previous;}
};
state.save=async()=>{if(!form.reportValidity())return false;const button=form.querySelector('button[type="submit"]');if(button.disabled||state.busy)return false;await form.onsubmit({preventDefault(){},target:form,submitter:button});return !state.failed&&(!form.isConnected||state.committed&&snapshot(form)===state.baseline);};
state.save=async()=>{if(!form.reportValidity())return false;const button=form.querySelector('button[type="submit"]');if(button.disabled||state.busy)return false;await form.onsubmit({preventDefault(){},target:form,currentTarget:form,submitter:button});return !state.failed&&(!form.isConnected||state.committed&&snapshot(form)===state.baseline);};
}
for(const [form] of forms)if(!form.isConnected)forms.delete(form);
}