SolidJSS
SolidJS3y ago
48 replies
Mathieu

Effects not running after a unhandled promise rejection event

When an unhandled error event occurs (e.g. by throwing new Error()), the ErrorBoundary is catching the error.

When an unhandled promise rejection occurs, the UI/JSX is being updated, I display the state of the resource in the JSX, and it switches from pending to errored, but the createEffect functions are not running:
createEffect(() => {
  console.log('userResource.state', userResource.state);
});

When displaying {userResource.state} from the JSX, it prints pending and then updates to errored because there was a promise rejection. It reacts.

However the createEffect above only logs pending once and will not log errored, while the JSX did react/get updated.

const EnsureAuthenticated: VoidComponent = () => {
  const [currentUser] = useCurrentUser();

  createEffect(() => {
    // doesn't react (logs only pending once)
    console.log('currentUser.state', currentUser.state);
  });

  return (
    // reacts (displays pending then errored)
    <>{currentUser.state}</>
  );
};
Was this page helpful?