I have a document object containing fields like title and name.
When an operation fails, I’m updating the document special field _failures with the error messages, for example I update
doc._failures.title = {failCode: 404, error: 'document unavailable'}
Now in sveltekit, when I display the fields, I check if there’s not a corresponding error in doc._failures.
My problem is that when I update _failures, Sveltekit doesn’t ‘realize’ I added fields into it, and never renders the failure messages.
I have a component tree I’m providing the root of with doc, but I’d like only nested fields to refresh if there’s a failure associated to them. For example doc.contact.email.personal
Any suggestions?
NOTE:
Just if you wonder how my code adds the _failure here’s a snippet:
if (result.type === 'failure') {
const error = JSON.parse(result.data).error;
console.log("Adding _failure to ", accessor)
_set(doc, '_failures.'+accessor, { failCode:result.status, error } )
}
>Solution :
Reactivity is based on assignments, _set is not an assignment.
You could add doc = doc afterwards to invalidate doc. This will cause any UI to update that uses doc reactively (i.e. if the reactivity chain is not broken that should be enough).