onlook icon indicating copy to clipboard operation
onlook copied to clipboard

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

Open Rish-it opened this issue 6 months ago • 1 comments

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

  • [x] 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:

https://github.com/user-attachments/assets/b5528a22-8ca6-4e22-8120-ed1cc28df66c

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.

Rish-it avatar Jun 07 '25 12:06 Rish-it

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 07 '25 12:06 vercel[bot]

Closing as duplicate to a similar fix. Thanks for this! Sorry about the issue. https://github.com/onlook-dev/onlook/pull/2097

Kitenite avatar Jun 07 '25 15:06 Kitenite