Skip to content

fix: prevent infinite restart loop by lazy-loading FreestyleSandboxes… #2101

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

Closed
wants to merge 2 commits into from

Conversation

Rish-it
Copy link
Contributor

@Rish-it Rish-it commented Jun 7, 2025

fix: prevent infinite restart loop by lazy-loading FreestyleSandboxes SDK

Description

Fixes infinite dev server restart loop caused by FreestyleSandboxes SDK initialization failure when FREESTYLE_API_KEY environment variable is not set.

Problem: The FreestyleSandboxes SDK was being instantiated at module import time, causing the dev server to crash and restart infinitely if the FREESTYLE_API_KEY environment variable was missing or undefined.

Solution:

  • Moved SDK instantiation from module-level to a lazy-loaded function (createFreestyleSdk)
  • SDK is now only created when the domain publishing mutation is actually called
  • Added proper error handling with clear messaging for missing API key
  • Allows the application to start successfully even without the FREESTYLE_API_KEY environment variable

Impact: Developers can now run the dev server without configuring the Freestyle API key, and will only get an error if they actually try to use the domain publishing feature.

Related Issues

Closes #2099

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Release
  • Refactor
  • Other (please describe):

Testing

  • Verified dev server starts successfully without FREESTYLE_API_KEY set
  • Confirmed domain publishing throws appropriate error when API key is missing
  • Tested that domain publishing works correctly when API key is provided
  • No breaking changes to existing functionality

Screenshots (if applicable)

Before:
Screenshot 2025-06-07 at 6 15 39 PM

After:

fixed.mov

Additional Notes

This fix resolves the exact issue described in #2099 where the FREESTYLE_API_KEY environment variable being optional in the schema but required at SDK instantiation time caused infinite restarts.

Copy link

vercel bot commented Jun 7, 2025

@Rish-it is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 05bf427 in 53 seconds. Click for details.
  • Reviewed 30 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. apps/web/client/src/server/api/routers/domain.ts:6
  • Draft comment:
    Good lazy-loading implementation: createFreestyleSdk checks for FREESTYLE_API_KEY properly, preventing early instantiation issues and infinite restart loops.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. apps/web/client/src/server/api/routers/domain.ts:31
  • Draft comment:
    Instantiating the SDK inside the mutation using createFreestyleSdk() defers initialization until the feature is used, which prevents startup crashes. Optionally, consider caching the SDK if instantiation is expensive.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_6t46U6XHpSDFQjQl

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@Kitenite
Copy link
Contributor

Kitenite commented Jun 7, 2025

Closing as duplicate to a similar fix. Thanks for this! Sorry about the issue.
#2097

@Kitenite Kitenite closed this Jun 7, 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.

[bug] bun dev command is stuck in an infinite restart loop!
2 participants