Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/async-data/AsyncView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, ReactNode } from 'react'
import { ReactElement, ReactNode } from 'react'

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The React import was removed but ReactElement and ReactNode types are still being imported. Since this component returns JSX (line 43, 47), React needs to be in scope for older React versions or the JSX transform configuration should be verified to ensure the automatic JSX runtime is enabled.

Suggested change
import { ReactElement, ReactNode } from 'react'
import React, { ReactElement, ReactNode } from 'react'

Copilot uses AI. Check for mistakes.

@lukasvice lukasvice Nov 21, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ok, I guess. It was automatically removed.

import { isFunction } from '../util'

type LoadingFunction = () => ReactNode
Expand All @@ -8,7 +8,7 @@ type ErrorFunction<Error> = (error: NonNullable<Error>) => ReactNode
type Props<Data, Error> = {
data?: Data
error?: Error
isLoading: boolean
isLoading?: boolean
renderLoading?: ReactNode | LoadingFunction
renderError?: ReactNode | ErrorFunction<Error>
} & (
Expand Down Expand Up @@ -36,15 +36,18 @@ const AsyncView = <Data, Error>(
allowMissingData = false,
} = props

if (isLoading) {
const isError = error !== null && error !== undefined
const hasData = data !== null && data !== undefined

if (isLoading || (isLoading === undefined && !hasData && !isError)) {

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback loading state logic !hasData && !isError could incorrectly treat the initial state (no data, no error) as loading even after a request completes with empty/falsy data. Consider whether empty arrays, empty strings, or false as valid data values should trigger loading state.

Suggested change
if (isLoading || (isLoading === undefined && !hasData && !isError)) {
// Show loading only if isLoading is true, or if isLoading is undefined and both data and error are undefined/null (initial state)
if (isLoading === true || (isLoading === undefined && !hasData && !isError)) {

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true, as we check explicitly for null and undefined.

return <>{isFunction(renderLoading) ? renderLoading() : renderLoading}</>
}

if (error !== null && error !== undefined) {
if (isError) {
return <>{isFunction(renderError) ? renderError(error) : renderError}</>
}

if ((data === undefined || data === null) && !allowMissingData) {
if (!hasData && !allowMissingData) {
throw new Error(
'Data passed into AsyncView was null or undefined. Use allowMissingData=true if this is intended.',
)
Expand Down