Skip to content

fix: set loading/success when erroring in useLoadScript#866

Open
davidjb wants to merge 2 commits intorakannimer:masterfrom
davidjb:patch-1
Open

fix: set loading/success when erroring in useLoadScript#866
davidjb wants to merge 2 commits intorakannimer:masterfrom
davidjb:patch-1

Conversation

@davidjb
Copy link
Copy Markdown

@davidjb davidjb commented Apr 20, 2026

When trying to use errorElement to display an error message when the Google Charts API doesn't load, I found that isLoading never goes to false, which means that the below only renders props.loader and can never render props.errorElement:

const ChartView: React.FC<ReactGoogleChartProps> = (props) => {
const { google, isLoading, error } = useLoadGoogleCharts(props);
if (isLoading) {
return props.loader ?? null;
}
if (error) {
return props.errorElement ?? null;
}

This PR solves the issue by calling setIsLoading(false); after setError(error);, and centralises this logic into a onError(error) handler, which consistently sets all three states for loading, error and success. Equally, onLoad has been adjusted slightly to clear an existing error if set -- such as when retrying or with a changed src.

Tests have been added to ensure that errorElement renders; these would have failed without the changes in this PR.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

@davidjb is attempting to deploy a commit to the rnim's projects Team on Vercel.

A member of the Team first needs to authorize it.

@davidjb davidjb changed the title fix: set loading/success when erroring in useLoadScript fix: set loading/success when erroring in useLoadScript Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant