SupabaseProvider has some methods for determining whether data is currently fetching, mutating & showing the user information about errors, however it's not optimally set up.
PROBLEMS
No way to define an error handling callback function (which makes it hard to do things like store an array of errors which the user must tick off, or show toast notifications on error)
No way to check for error or success in subsequent actions after running an element action to mutate data
Hard to distinguish between errors that happen on mutate vs errors that happen on fetch of data
Mutation errors clear when data is refetched, which means the user may not even see that error has happened.
Hard to determine if we are currently fetching or mutating data
Hard to determine if a single row is currently "optimistic" or fully saved.
optimisticData function when running mutate() in element actions is not called correctly
//current way of calling optimisticData function
mutate(addRow(rowForSupabase, optimisticRow, optimisticFunc), {
populateCache: true,
optimisticData: optimisticFunc(data, optimisticRow),
...
//better way of calling optimisticData function gauranteeing latest current data from cache is used
mutate(addRow(rowForSupabase, optimisticRow, optimisticFunc), {
populateCache: false,
optimisticData: (currentData) => optimisticFunc(currentData, optimisticRow)
...
SUGGESTIONS TO SOLVE
A package following similar pattern as Plasmic-Supabase's SupabaseProvider but working with a different API is seen here (Plasmic-Knack -> KnackProvider component). I suggest adopting many of the same patterns in Plasmic-Supabase including:
isMutating state exported as context
isLoading state exported as context
fetcher error exported as context (called getRecordsError in the linked package). Set up in a way that mutation errors are NOT included in this
onError callback function available & triggered on Create, read, update or delete
Element actions that mutate data return either data or an error so subsequent actions can be used to handle errors
Giving errors a unique ID & information about what action was attempted (Create, read, update or delete)
optimistic database rows given parameters (isOptimistic, optimisticId) so it's easy to determine they are optimistic and currently saving
fix the way optimisticData is called during mutate() as per details above
Video: a well-developed component using Plasmic-Knack is shown in this video. It demonstrates the key suggestsions above: it has full CRUD with optimistic mutations, good error handling & detailed loading notifications
CONTEXT:
SupabaseProvider has some methods for determining whether data is currently fetching, mutating & showing the user information about errors, however it's not optimally set up.
PROBLEMS
SUGGESTIONS TO SOLVE
A package following similar pattern as Plasmic-Supabase's SupabaseProvider but working with a different API is seen here (Plasmic-Knack -> KnackProvider component). I suggest adopting many of the same patterns in Plasmic-Supabase including:
mutate()
as per details aboveVideo: a well-developed component using Plasmic-Knack is shown in this video. It demonstrates the key suggestsions above: it has full CRUD with optimistic mutations, good error handling & detailed loading notifications