Repository navigation
False unsaved-changes prompt, slot save/draft hooks, and dirty-form leave guards on every page #2734
wychoong
started this conversation in
Feedback & Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Three related pain points on panel edit pages: a false dirty prompt on product edit, no way for slots to join Save/drafts, and leave-confirmation that is tied to drafts instead of being a panel-wide form behaviour.
1. False unsaved-changes prompt
Open a product, change nothing, navigate away. The leave confirmation still fires:
Same on a fresh load with no draft. The page is dirty before anyone types.
Product edit is fully draft-backed (
useEditDraftinpackages/panel/resources/js/pages/products/Edit.vue). Dirty tracking compares the form to a pristine snapshot. Some fields look like they save immediately, or don't round-trip the same shape as the snapshot (translatable fields, attribute values, tags, availability, variant keys), soisDirtyis true on load.Expected: open the page, make no edits, leave without a prompt.
This isn't unique to products. The same composable backs:
2. How do slots join Save and drafts?
I'm injecting Vue components through slots (e.g. product edit
content:after). The slot gets the record prop, but I don't see a way to:Docs cover injecting a component into a zone. They don't cover save. The example SEO card keeps state local.
What would help is process hooks on the edit page, something like:
beforeSave/afterSaved— page Save / commitbeforeDraftSave/afterDraftSaved— autosave / draft persistSlot components could register, persist their own fields, and stay consistent with Lunar's draft instead of a second save path that fights dirty tracking.
3. Config to disable drafts — and still prompt on dirty navigate
Not every store wants Shopify-style drafts. Some want a normal form: edit, save, done.
lunar.panel.draftstoday only has TTL:A flag such as
lunar.panel.drafts.enabled(defaulttrue) would let a host turn drafts off: no autosave, no leave-as-draft prompt, Save writes through.If drafts are off, the dirty-form leave prompt should still exist. Staff who typed into a form and click away should get "You have unsaved changes" — just without "Your edits will be kept as a draft." Today's copy is draft-specific:
4. Dirty leave-guard should be all pages, including add-ons / extensions
This is not true today. I checked the panel JS:
The only
router.on('before')/beforeunloadleave guard lives insideuseEditDraft:That composable is only used on the draft-backed edit pages listed above.
Everything else uses Inertia
useFormwith no leave confirmation, including:Add-ons do not get this for free either.
useEditDraftis exported from@lunarphp/panel, so an add-on can opt in — but only if it uses drafts. The example add-on settings page usesuseFormand has no dirty prompt:So:
useEditDraftthemselvesI'd like a panel-wide dirty leave-guard for any form page — first-party, add-on, and section extension — independent of drafts. Drafts can keep using it with the "kept as a draft" copy; everyone else gets a plain unsaved-changes confirm. Opting in could be automatic for
useForm/ a smallusePanelFormwrapper exported from@lunarphp/panel, rather than each add-on reinventingrouter.on('before').Refs:
All reactions