Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: StoryClient Initialization in StoryProvider #372

Closed
wants to merge 1 commit into from

Conversation

Himess
Copy link

@Himess Himess commented Dec 28, 2024

Description

This PR fixes an issue where the StoryClient was being re-initialized on every render inside the StoryProvider component. This led to an infinite re-render loop and impacted the application’s performance.

Problem & Solution:

The StoryClient was being re-created on every render, causing an infinite re-render loop. By implementing lazy initialization, the client is now created only once when needed, preventing unnecessary renders and improving performance.

Key Changes:

  1. Lazy Initialization: The StoryClient initialization is moved to a useEffect hook, ensuring it is created only once when the component is first mounted.
  2. Loading State: A loading state is introduced during the client initialization process to enhance user experience, ensuring that the component remains stable while the client is being set up.

Test Plan

Steps to Verify:

  1. Initial Render:

    • Ensure that StoryClient is created only once during the component's first render.
    • Confirm that no re-renders are triggered unnecessarily due to the client being re-created.
  2. Loading State:

    • Verify that a loading state is displayed while the StoryClient is being initialized.
    • Confirm that the loading state disappears once the client is initialized and the child components are rendered.
  3. Edge Cases:

    • Test the component with various configurations of StoryClient to ensure no unexpected errors or performance issues occur.

Related Issue

N/A


Notes

This update optimizes the performance of the StoryProvider component and ensures the StoryClient is only initialized when needed, reducing unnecessary renders. Minor refactoring has also been applied to maintain compatibility.

…toryProvider

This change fixes an issue where the StoryClient was being re-created on every render, causing an infinite re-render loop. 
By lazily initializing the StoryClient only once, the component will now only create the client when it's first needed, avoiding unnecessary renders.

Additionally, a loading state is added to improve user experience while the client is being initialized.
This ensures that the component doesn't break or display unexpected behavior during the initialization process.
@Himess Himess closed this by deleting the head repository Jan 1, 2025
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