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

[bugfix] disable analytics manager on SSR #167

Merged
merged 5 commits into from
Nov 13, 2024

Conversation

franjohn21
Copy link
Contributor

Seeing this error when using this package in a node app. Think we should just be safe and not save to local storage in the even the environment doesn't support it.

const cachedEventIdsValue = localStorage.getItem("tdk-analytics-event-ids");
                              ^
ReferenceError: localStorage is not defined

Copy link

changeset-bot bot commented Nov 13, 2024

🦋 Changeset detected

Latest commit: 654619b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@treasure-dev/tdk-react Patch
@treasure-dev/tdk-core Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link

vercel bot commented Nov 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
tdk-examples-connect ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 9:52pm
tdk-examples-magicswap ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 9:52pm

@franjohn21
Copy link
Contributor Author

franjohn21 commented Nov 13, 2024

Actually now that I'm thinking more about this fix -- this is a bandaid. Should the AnalyticsManager even be running in SSR context? What do we want to track?

If i follow the code correctly I think there's technically a memory leak -- on every new render we'd initialize a new AnalyticsManager which invokes a new setInterval. This means there could be an ever increasing number of intervals added and will crash the server. This might not ever be a problem in vercel/lambda serverless functions architecture but if an app is a singular node server it's an issue and we shouldn't assume the SSR is running in a serverless function.

@franjohn21 franjohn21 changed the title [bugfix] mock localStorage for environments that dont support it globally (node) [bugfix] disable analytics manager on SSR Nov 13, 2024
@franjohn21 franjohn21 force-pushed the fix/local-storage-in-non-browser-env branch from d986029 to 654619b Compare November 13, 2024 21:52
@alecananian alecananian merged commit 78bb7e6 into main Nov 13, 2024
4 checks passed
@alecananian alecananian deleted the fix/local-storage-in-non-browser-env branch November 13, 2024 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants