@@ -549,8 +549,28 @@ export async function getPluginContext(): Promise<PluginContext> {
549549 id : uniqueHeaderRowNames . find ( name => name === field . name ) ?? uniqueHeaderRowNames [ index ] ?? field . name ,
550550 } ) )
551551 } else {
552- ignoredColumns = v . parse ( v . array ( v . string ( ) ) , JSON . parse ( rawIgnoredColumns ) )
553552 slugColumn = storedSlugColumn
553+ const result = v . safeParse ( v . pipe ( v . string ( ) , v . parseJson ( ) , v . array ( v . string ( ) ) ) , rawIgnoredColumns )
554+
555+ if ( result . success ) {
556+ ignoredColumns = result . output
557+ } else if ( framer . isAllowedTo ( "ManagedCollection.setPluginData" ) ) {
558+ ignoredColumns = await salvageIgnoredColumns ( rawIgnoredColumns , ignoredColumns =>
559+ collection . setPluginData ( PLUGIN_IGNORED_COLUMNS_KEY , JSON . stringify ( ignoredColumns ) )
560+ )
561+
562+ // Notify the user to be sure they're aware of the issue, to be sure they acknowledge it make it persistent
563+ framer . notify ( "Some columns couldn’t be restored. Please review your ignored columns in Manage." , {
564+ variant : "warning" ,
565+ durationMs : Infinity ,
566+ } )
567+ } else {
568+ ignoredColumns = [ ]
569+
570+ framer . notify ( "Configuration of ignored columns is invalid. You need write permissions to fix it." , {
571+ variant : "error" ,
572+ } )
573+ }
554574 }
555575
556576 // We should not hash ignored fields since they are not synced to Framer,
@@ -611,3 +631,22 @@ export const useSyncSheetMutation = ({
611631 onError,
612632 } )
613633}
634+
635+ async function salvageIgnoredColumns (
636+ rawIgnoredColumns : unknown ,
637+ setIgnoredColumns : ( ignoredColumns : string [ ] ) => Promise < void >
638+ ) : Promise < string [ ] > {
639+ let result : string [ ]
640+
641+ const atLeastAnArrayResult = v . safeParse ( v . pipe ( v . string ( ) , v . parseJson ( ) , v . array ( v . unknown ( ) ) ) , rawIgnoredColumns )
642+
643+ if ( atLeastAnArrayResult . success ) {
644+ result = atLeastAnArrayResult . output . filter ( i => typeof i === "string" )
645+ } else {
646+ result = [ ]
647+ }
648+
649+ await setIgnoredColumns ( result )
650+
651+ return result
652+ }
0 commit comments