Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 17, 2025

  • Understand the existing lazy implementation and testing structure
  • Design the useLazy hook interface based on issue requirements
  • Implement LazyProvider context to track lazy component states globally
  • Implement useLazy hook that can track loading states of lazy components
  • Add the hook to support preloading and state tracking outside of Suspense
  • Create tests for the new useLazy functionality
  • Update exports to include new useLazy hook and LazyProvider
  • Test the implementation to ensure it works as expected
  • Update documentation if needed

Implementation Details

New Components Added:

  1. LazyProvider: Context provider that manages loading states of lazy components globally
  2. useLazy: Hook that accepts a lazy component and returns { isLoading, isLoaded, load }

Key Features:

  • ✅ Track loading state outside of Suspense boundaries
  • ✅ Preload lazy components via load() method
  • ✅ Prevent duplicate loading when already loading/loaded
  • ✅ Independent state tracking for multiple lazy components
  • ✅ Error handling that resets loading state on failures

Usage Example:

import { lazy, useLazy, LazyProvider } from '@suspensive/react'

const Page1 = lazy(() => import('./Page1'))

const NavItemToPage1 = () => {
  const lazyPage1 = useLazy(Page1)
  return (
    <Link onMouseEnter={() => lazyPage1.load()} to='/page1'>
      to Page1 {lazyPage1.isLoading ? 'loading...' : lazyPage1.isLoaded ? 'loaded' : 'not loaded'}
    </Link>
  )
}

Fixes #1666.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

vercel bot commented Sep 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
v2.suspensive.org Ready Ready Preview Comment Sep 24, 2025 4:01pm
v3.suspensive.org Error Error Sep 24, 2025 4:01pm
visualization.suspensive.org Ready Ready Preview Comment Sep 24, 2025 4:01pm

Copy link

changeset-bot bot commented Sep 17, 2025

⚠️ No Changeset found

Latest commit: 40ecb1f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coauthors bot commented Sep 24, 2025

People can be co-author:

Candidate Reasons Count Add this as commit message
@Copilot #1749 1 Co-authored-by: Copilot <[email protected]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: useLazy(Comp)

3 participants