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

Should shutdown unset _fs_initialized? #108

Open
quisido opened this issue Nov 17, 2021 · 2 comments
Open

Should shutdown unset _fs_initialized? #108

quisido opened this issue Nov 17, 2021 · 2 comments

Comments

@quisido
Copy link

quisido commented Nov 17, 2021

I have a React useEffect hook that calls init() on mount. There is currently no cleanup function to un-initialize FullStory.

When this React component mounts, it initialized FullStory (expected behavior).

If this component unmounts, then remounts, it emits a console warning that FullStory has already been initialized and not to initialize it again.

This is fair. In the live app, this component doesn't unmount. However, in unit tests, the application mounts and unmounts multiple times when testing behavior. As a result, this component mounts, initializes FullStory ✅, runs a test, unmounts, then mounts, initializes FullStory ⚠ (warning), runs a test, unmounts.

I checked into adding shutdown as a cleanup step, but it does not appear as if shutdown resets the _fs_initalized variable.

Any advice?

Is "unset _fs_initialized in shutdown" a valid feature request here?

@timtucker-dte
Copy link

I'm currently calling isInitialized in hooks as a way of avoiding this.

i.e.:

import { init, isInitialized } from '@fullstory/browser';

const snippetOptions: SnippetOptions = {
	orgId: "foo"
};

export function FullStoryInit(props: PropsWithChildren): ReactNode {
	const fullStoryInitialized = isInitialized();

	useEffect(() => {
		if (fullStoryInitialized) {
			return;
		}
		init(snippetOptions, readyCallback);
	}, [fullStoryInitialized]);

	return props.children;
}

@quisido
Copy link
Author

quisido commented Feb 7, 2025

I'm currently calling isInitialized in hooks as a way of avoiding this.

i.e.:

import { init, isInitialized } from '@fullstory/browser';

const snippetOptions: SnippetOptions = {
	orgId: "foo"
};

export function FullStoryInit(props: PropsWithChildren): ReactNode {
	const fullStoryInitialized = isInitialized();

	useEffect(() => {
		if (fullStoryInitialized) {
			return;
		}
		init(snippetOptions, readyCallback);
	}, [fullStoryInitialized]);

	return props.children;
}

I think this is great for 90% of projects. One concern I have with this at the abstract level, making it relevant to the package itself instead of the consumer, is if you need to change the init options mid-run to be a separate FullStory account. I expect to shutdown the previous instance, then init the new one.

This matters in my application unit tests because my application expects to support multiple FullStory consumers. Even if the FullStory instance doesn't swap mid-render, it does swap between one unit test and the next.

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

No branches or pull requests

2 participants