Skip to content

Infinite Re-render Bug in layoutContexts.tsx #3

@Abhrxdip

Description

@Abhrxdip

Can crash the application

layoutContexts.tsx:
useEffect(() => {
if (
(path === '/nestify' || path.includes('development-tools')) &&
Gleap.getInstance().initialized // ⚠️ BUG: Returns new value each call
) {
Gleap.destroy();
} else if (
!Gleap.getInstance().initialized && // ⚠️ BUG: Causes infinite loop
path !== '/nestify' &&
!path.includes('development-tools')
) {
Gleap.setUseCookies(true);
Gleap.initialize(process.env.GLEAP_API_KEY || '');
}
}, [path, Gleap.getInstance().initialized]); // ⚠️ Dependency creates new reference

Issue: Gleap.getInstance().initialized in the dependency array returns a new reference on each render, causing infinite re-renders.

Fix: Store the initialized state in a variable or remove from dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions