@@ -146,6 +146,12 @@ import { useRegisteredMetadataDefaultInspector } from './default-inspector-regis
146146import { useMetadataLocale , t , tFormat , translateMetadataType , translateValidationMessage } from './i18n.js' ;
147147import { JsonSourceEditor } from './JsonSourceEditor.js' ;
148148import { validateMetadataDraft , hasClientValidator , type DraftMode } from './clientValidation.js' ;
149+ import {
150+ draftEnvelopeDiagnostics ,
151+ editedItemDiagnostics ,
152+ withServerOnlyErrors ,
153+ type ServerDiagnostics ,
154+ } from './draftVerdict.js' ;
149155import { describeIssuePath , issueSlicePath , issueSliceFingerprint } from './issuePath.js' ;
150156import { buildCreateModeBody , seedStructuralDefaults , unsetSeedPlaceholders } from './createBody.js' ;
151157import { errorCodeIs , errorCodeIsAnyOf } from '@object-ui/types' ;
@@ -750,6 +756,18 @@ function MetadataResourceEditPageImpl({
750756 ( ) => ( createMode && ! createDirty ? [ ] : issues ) ,
751757 [ createMode , createDirty , issues ] ,
752758 ) ;
759+ // Per-item draft pending publish (mode=draft saves land here).
760+ // When non-null, the editor is "viewing the draft" and we surface
761+ // Publish / Discard-draft actions.
762+ const [ hasDraft , setHasDraft ] = React . useState ( false ) ;
763+ // objectstack#26707 — the pending draft's own `_diagnostics`, kept from each
764+ // draft read (load, save, publish) before its decorations are stripped.
765+ const [ draftDiagnostics , setDraftDiagnostics ] = React . useState < ServerDiagnostics | undefined > ( undefined ) ;
766+ // The server verdict on the body on screen (see `draftVerdict.ts`).
767+ const serverDiagnostics = React . useMemo (
768+ ( ) => editedItemDiagnostics ( { hasDraft, draftDiagnostics, layered } ) ,
769+ [ hasDraft , draftDiagnostics , layered ] ,
770+ ) ;
753771 // Server-computed diagnostics handed to a canvas Preview (e.g. the flow
754772 // Problems panel + on-canvas badges). Errors prefer the live client-side Zod
755773 // issues when a client validator exists (so they track every keystroke);
@@ -758,12 +776,13 @@ function MetadataResourceEditPageImpl({
758776 const previewDiagnostics = React . useMemo <
759777 Array < { path ?: string ; message : string ; severity : 'error' | 'warning' } >
760778 > ( ( ) => {
761- const diag = ( layered as any ) ?. _diagnostics as
762- | { errors ?: Array < { path : string ; message : string } > ; warnings ?: Array < { path : string ; message : string } > }
763- | undefined ;
764- const errs = hasClientValidator ( type , draftMode )
765- ? displayIssues . map ( ( i ) => ( { path : i . path , message : translateValidationMessage ( i . message , locale ) } ) )
766- : ( diag ?. errors ?? [ ] ) . map ( ( i ) => ( { path : i . path , message : translateValidationMessage ( i . message , locale ) } ) ) ;
779+ // objectstack#26707 — the verdict on the body on screen: the pending
780+ // draft's (which carries what its publish would refuse) while one is held.
781+ const diag = serverDiagnostics ;
782+ const errs = ( hasClientValidator ( type , draftMode )
783+ ? withServerOnlyErrors ( displayIssues , diag ?. errors )
784+ : ( diag ?. errors ?? [ ] )
785+ ) . map ( ( i ) => ( { path : i . path , message : translateValidationMessage ( i . message , locale ) } ) ) ;
767786 const warns = ( diag ?. warnings ?? [ ] ) . map ( ( i ) => ( {
768787 path : i . path ,
769788 message : translateValidationMessage ( i . message , locale ) ,
@@ -772,11 +791,7 @@ function MetadataResourceEditPageImpl({
772791 ...errs . map ( ( e ) => ( { path : e . path || undefined , message : e . message , severity : 'error' as const } ) ) ,
773792 ...warns . map ( ( w ) => ( { path : w . path || undefined , message : w . message , severity : 'warning' as const } ) ) ,
774793 ] ;
775- } , [ layered , displayIssues , type , locale , draftMode ] ) ;
776- // Per-item draft pending publish (mode=draft saves land here).
777- // When non-null, the editor is "viewing the draft" and we surface
778- // Publish / Discard-draft actions.
779- const [ hasDraft , setHasDraft ] = React . useState ( false ) ;
794+ } , [ serverDiagnostics , displayIssues , type , locale , draftMode ] ) ;
780795 const [ publishing , setPublishing ] = React . useState ( false ) ;
781796 // Bumped by destructive operations (rollback / discard-draft) to
782797 // force the load effect to refetch layered + draft state.
@@ -1166,10 +1181,14 @@ function MetadataResourceEditPageImpl({
11661181 if ( cancelled ) return ;
11671182 const draftResp = draftRead . answer ;
11681183 setLayered ( lay ) ;
1184+ // objectstack#26707 — a pending draft is judged by its own read, whose
1185+ // verdict carries what its publish would refuse.
1186+ const loadDraftDiagnostics = extractDraftBody ( draftResp ) ? draftEnvelopeDiagnostics ( draftResp ) : undefined ;
1187+ setDraftDiagnostics ( loadDraftDiagnostics ) ;
11691188 // Surface server-computed load-time validation errors as inline
11701189 // SchemaForm issues — operators see what's wrong with the
11711190 // saved metadata immediately, not just on the next Save round-trip.
1172- const loadDiag = ( lay as any ) ?. _diagnostics as
1191+ const loadDiag = loadDraftDiagnostics ?? ( lay as any ) ?. _diagnostics as
11731192 | { valid : boolean ; errors ?: Array < { path : string ; message : string } > }
11741193 | undefined ;
11751194 if ( loadDiag && loadDiag . valid === false && Array . isArray ( loadDiag . errors ) ) {
@@ -1781,6 +1800,7 @@ function MetadataResourceEditPageImpl({
17811800 if ( ! layerless ) setLayered ( lay ) ;
17821801 const draftReal = extractDraftBody ( draftResp ) ;
17831802 setHasDraft ( ! ! draftReal ) ;
1803+ setDraftDiagnostics ( draftReal ? draftEnvelopeDiagnostics ( draftResp ) : undefined ) ;
17841804 // The served draft is the whole document the save just stored (see the
17851805 // load effect, objectui#10765): take it as-is. ⛔ Not spread over
17861806 // `effective` — that is the PUBLISHED layer, and a spread would bring a
@@ -2015,6 +2035,7 @@ function MetadataResourceEditPageImpl({
20152035 setLayered ( lay ) ;
20162036 const draftReal = extractDraftBody ( draftResp ) ;
20172037 setHasDraft ( ! ! draftReal ) ;
2038+ setDraftDiagnostics ( draftReal ? draftEnvelopeDiagnostics ( draftResp ) : undefined ) ;
20182039 // After a publish the promoted body IS `effective` and the draft row is
20192040 // normally gone; a draft that does remain is a whole document and is
20202041 // taken as-is (objectui#10765). ⛔ Not spread over `effective`: the
@@ -2077,6 +2098,7 @@ function MetadataResourceEditPageImpl({
20772098 setDraft ( fresh ) ;
20782099 draftSnapshotRef . current = fresh ;
20792100 setHasDraft ( false ) ;
2101+ setDraftDiagnostics ( undefined ) ;
20802102 // objectui#12303 — the discard is said, naming what it discarded, through
20812103 // the console's shared toast (`sonner`, the one Studio's publish uses).
20822104 // Only here, after the DELETE and the re-read landed: a refused discard
@@ -2847,27 +2869,20 @@ function MetadataResourceEditPageImpl({
28472869 // a structural problem without saving first. The same
28482870 // errors are also threaded into SchemaForm as `issues`
28492871 // and rendered inline next to each broken field.
2850- const diag = ( layered as any ) ?. _diagnostics as
2851- | {
2852- valid : boolean ;
2853- errors ?: Array < { path : string ; message : string } > ;
2854- warnings ?: Array < { path : string ; message : string } > ;
2855- }
2856- | undefined ;
2872+ // objectstack#26707 — the pending draft's verdict while one is held.
2873+ const diag = serverDiagnostics ;
28572874 // When client-side Zod validation is available for this
28582875 // type, drive the error portion of the banner from the
28592876 // live `issues` state instead of the stale load-time
28602877 // diagnostics, so it stays in sync with every keystroke.
28612878 // Warnings remain server-sourced (Zod doesn't model them).
2862- const liveErrors = hasClientValidator ( type , draftMode )
2863- ? issues . map ( ( i ) => ( {
2864- path : i . path ,
2865- message : translateValidationMessage ( i . message , locale ) ,
2866- } ) )
2867- : ( diag ?. errors ?? [ ] ) . map ( ( i ) => ( {
2868- ...i ,
2869- message : translateValidationMessage ( i . message , locale ) ,
2870- } ) ) ;
2879+ const liveErrors = ( hasClientValidator ( type , draftMode )
2880+ ? withServerOnlyErrors ( issues , diag ?. errors )
2881+ : ( diag ?. errors ?? [ ] )
2882+ ) . map ( ( i ) => ( {
2883+ path : i . path ,
2884+ message : translateValidationMessage ( i . message , locale ) ,
2885+ } ) ) ;
28712886 const liveValid = hasClientValidator ( type , draftMode )
28722887 ? liveErrors . length === 0
28732888 : diag ?. valid !== false ;
0 commit comments