@@ -3720,11 +3720,32 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
37203720 // Why the cell an edit was asked of opens no editor, drawn on that cell.
37213721 const [ cellNotice , setCellNotice ] = useState < { rowIndex : number ; colIndex : number ; text : string } | null > ( null ) ;
37223722
3723- // objectstack#35795 — an edit asked while the host still reads what decides
3724- // it (`GridCellFacts.checking`), asked again when that read settles. One at
3725- // a time: a newer ask, another selected cell or an open editor drops it.
3726- const waitingEditRef = useRef < { rowKey : PendingRowKey ; columnKey : string ; seed ?: { value : unknown } } | null > ( null ) ;
3727- const retryWaitingEditRef = useRef < ( waiting : { rowKey : PendingRowKey ; columnKey : string ; seed ?: { value : unknown } } ) => void > ( ( ) => { } ) ;
3723+ // objectstack#35795 — an edit or a write asked while the host still reads
3724+ // what decides it (`GridCellFacts.checking`), asked again when that read
3725+ // settles. One at a time: a newer ask, another selected cell or an open
3726+ // editor drops it.
3727+ type WaitingAct = { rowKey : PendingRowKey ; columnKey : string ; run : ( rowIndex : number , colIndex : number ) => void } ;
3728+ const waitingEditRef = useRef < WaitingAct | null > ( null ) ;
3729+ const retryWaitingEditRef = useRef < ( waiting : WaitingAct ) => void > ( ( ) => { } ) ;
3730+ /** Say on the cell that it is being checked, and ask `run` again once `settled` settles. */
3731+ const waitForChecking = (
3732+ rowIndex : number ,
3733+ colIndex : number ,
3734+ row : any ,
3735+ col : TableColumn ,
3736+ checking : { text : string ; settled : Promise < unknown > } ,
3737+ run : WaitingAct [ 'run' ] ,
3738+ ) => {
3739+ setCellNotice ( { rowIndex, colIndex, text : checking . text } ) ;
3740+ const waiting : WaitingAct = { rowKey : pendingRowKeyOf ( row ) , columnKey : col . accessorKey , run } ;
3741+ waitingEditRef . current = waiting ;
3742+ const retry = ( ) => {
3743+ if ( waitingEditRef . current !== waiting ) return ;
3744+ waitingEditRef . current = null ;
3745+ retryWaitingEditRef . current ( waiting ) ;
3746+ } ;
3747+ checking . settled . then ( retry , retry ) ;
3748+ } ;
37283749
37293750 const selectCell = ( rowIndex : number , colIndex : number ) => {
37303751 const row = paginatedData [ rowIndex ] ;
@@ -3819,15 +3840,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
38193840 // Asked again when what decides it has been read; it says so meanwhile.
38203841 const checking = factsOf ( row , col ) ?. checking ;
38213842 if ( checking ) {
3822- setCellNotice ( { rowIndex, colIndex, text : checking . text } ) ;
3823- const waiting = { rowKey : pendingRowKeyOf ( row ) , columnKey : col . accessorKey , ...( seed ? { seed } : { } ) } ;
3824- waitingEditRef . current = waiting ;
3825- const retry = ( ) => {
3826- if ( waitingEditRef . current !== waiting ) return ;
3827- waitingEditRef . current = null ;
3828- retryWaitingEditRef . current ( waiting ) ;
3829- } ;
3830- checking . settled . then ( retry , retry ) ;
3843+ waitForChecking ( rowIndex , colIndex , row , col , checking , ( r , c ) => attemptEdit ( r , c , seed ) ) ;
38313844 return ;
38323845 }
38333846 waitingEditRef . current = null ;
@@ -3853,7 +3866,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
38533866 const rowIndex = paginatedData . findIndex ( ( r ) => pendingRowKeyOf ( r ) === waiting . rowKey ) ;
38543867 const colIndex = columns . findIndex ( ( c ) => c . accessorKey === waiting . columnKey ) ;
38553868 if ( rowIndex < 0 || colIndex < 0 ) return ;
3856- attemptEdit ( rowIndex , colIndex , waiting . seed ) ;
3869+ waiting . run ( rowIndex , colIndex ) ;
38573870 } ;
38583871
38593872 /** Write a value into a cell without an editor: the commit `saveEdit` makes. */
@@ -3885,12 +3898,14 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
38853898 }
38863899 const value = valueOf ( row , col ) ;
38873900 if ( value === undefined ) return ;
3888- // Nothing is written while what decides the write is still being read.
3901+ // Written once what decides the write has been read, the value worked out
3902+ // again then; it says so meanwhile.
38893903 const checking = factsOf ( row , col ) ?. checking ;
38903904 if ( checking ) {
3891- setCellNotice ( { rowIndex, colIndex, text : checking . text } ) ;
3905+ waitForChecking ( rowIndex , colIndex , row , col , checking , ( r , c ) => writeCell ( r , c , valueOf ) ) ;
38923906 return ;
38933907 }
3908+ waitingEditRef . current = null ;
38943909 commitCellValue ( row , col . accessorKey , value ) ;
38953910 } ;
38963911
0 commit comments