Skip to content

Conversation

@lukasvice
Copy link
Contributor

No description provided.

@lukasvice lukasvice self-assigned this Nov 21, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR makes the isLoading prop optional in the AsyncView component and adds automatic loading state inference based on data and error availability.

Key Changes:

  • Made isLoading prop optional in the component's type definition
  • Implemented fallback logic to automatically determine loading state when isLoading is undefined
  • Refactored condition checks to use extracted boolean variables for improved readability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,4 +1,4 @@
import React, { ReactElement, ReactNode } from 'react'
import { ReactElement, ReactNode } from 'react'
Copy link

Copilot AI Nov 21, 2025

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.
Copy link
Contributor Author

@lukasvice lukasvice Nov 21, 2025

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.

const isError = error !== null && error !== undefined
const hasData = data !== null && data !== undefined

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

Copilot AI Nov 21, 2025

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
Contributor 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.

@lukasvice lukasvice changed the title make is-loading optional add fallback behaviour for is-loading Nov 21, 2025
Copy link
Contributor

@SirCotare SirCotare left a comment

Choose a reason for hiding this comment

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

nice! 💯

@lukasvice lukasvice merged commit a668fd2 into main Nov 21, 2025
6 checks passed
@lukasvice lukasvice deleted the optional-is-loading branch November 21, 2025 08:42
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.

3 participants