Understanding action return values

My understanding is that actions that don't return any value are automatically cleared. When I look at the code, it seems that when an action returns a falsey value, it should also be automatically cleared. However, I don't see this happening in practice. Consider the following code:
import {
query,
action,
createAsync,
useAction,
useSubmission,
} from "@solidjs/router";

let count = 0;

const getCount = query(async () => {
return count;
}, "getCount");

const increment = action(async () => {
count += 1;

if (count === 2) {
return { error: "Error" };
}

return undefined;
});

export default function Home() {
const c = createAsync(() => getCount());
const i = useAction(increment);
const submission = useSubmission(increment);

return (
<div>
<div>Error: {submission.result?.error}</div>
<div>Count: {c()}</div>
<button onClick={() => i()}>Add</button>
</div>
);
}
import {
query,
action,
createAsync,
useAction,
useSubmission,
} from "@solidjs/router";

let count = 0;

const getCount = query(async () => {
return count;
}, "getCount");

const increment = action(async () => {
count += 1;

if (count === 2) {
return { error: "Error" };
}

return undefined;
});

export default function Home() {
const c = createAsync(() => getCount());
const i = useAction(increment);
const submission = useSubmission(increment);

return (
<div>
<div>Error: {submission.result?.error}</div>
<div>Count: {c()}</div>
<button onClick={() => i()}>Add</button>
</div>
);
}
When the action returns undefined or null, the error is not cleared when the count is incremented, which is expected. However, if it returns 0 or another falsey value, the behavior is different. Am I missing something?
GitHub
solid-router/src/data/action.ts at 30f08665e87829736a9333d55863d279...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router
2 Replies
ladybluenotes
ladybluenotes4w ago
@core-team anyone able to answer this? he’s updating the docs
ryansolid
ryansolid4w ago
Hmm.. I wonder if it is getting serialized in a weird way. No.. this is pure client side example. Returning null/undefined should clear it when it completes. It only keeps things around when they return a value. To be fair there may be a bug here. I think that code probably should be (result != null). Falsey values like false and definitely 0 probably should stick around. But undefined/null definitely should be gone.

Did you find this page helpful?