8000 fix: Don't throw error if TamboProvider used outside browser by MichaelMilstead · Pull Request #271 · tambo-ai/tambo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Don't throw error if TamboProvider used outside browser #271

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

Merged
merged 2 commits into from
Apr 4, 2025

Conversation

MichaelMilstead
Copy link
Collaborator

Changes the error throw to an error log since in NextJS the provider is rendered once on server-side.

@charliecreates charliecreates bot requested a review from CharlieHelps April 4, 2025 00:11
Copy link
8000
vercel bot commented Apr 4, 2025

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

Name Status Preview Comments Updated (UTC)
showcase ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 4, 2025 0:11am

@github-actions github-actions bot added the fix label Apr 4, 2025
@MichaelMilstead MichaelMilstead enabled auto-merge (squash) April 4, 2025 00:11
Copy link
@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the change meets the goal of avoiding server-side errors by logging instead of throwing, allowing the remainder of the component to render in non-browser environments may lead to unintended side effects. A conditional early return could improve the robustness and maintainability of the code.

Summary of changes

Summary

  • Replaced the thrown error with a console.error log when window is undefined.
  • Updated the inline comment from 'explode if we're not in a browser' to 'Should only be used in browser'.

Comment on lines +41 to +43
// Should only be used in browser
if (typeof window === "undefined") {
throw new Error("TamboProvider must be used within a browser");
console.error("TamboProvider must be used within a browser");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update successfully avoids crashing on the server by logging the error instead of throwing. However, the component continues rendering even when window is undefined, which might lead to unexpected behavior if subsequent browser-specific APIs are used. Consider returning null immediately after logging the error to safely bypass rendering in non-browser contexts. Reply with "@CharlieHelps yes please" if you'd like me to add a comm 8000 it with this suggestion.

if (typeof window === 'undefined') {
console.error('TamboProvider must be used within a browser');
return null;
}

@charliecreates charliecreates bot removed the request for review from CharlieHelps April 4, 2025 00:12
@MichaelMilstead MichaelMilstead merged commit 0390fb1 into main Apr 4, 2025
6 checks passed
@MichaelMilstead MichaelMilstead deleted the milst/react/use-in-browser-error branch April 4, 2025 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0