Skip to content

feat(studio): warn if studio is imported but not initialized - #525

Open
0xTHAC0 wants to merge 1 commit into
theatre-js:mainfrom
0xTHAC0:feat/studio-init-warning-tests
Open

feat(studio): warn if studio is imported but not initialized#525
0xTHAC0 wants to merge 1 commit into
theatre-js:mainfrom
0xTHAC0:feat/studio-init-warning-tests

Conversation

@0xTHAC0

@0xTHAC0 0xTHAC0 commented Aug 12, 2026

Copy link
Copy Markdown

Summary

Addresses #21 — adds a helpful console.warn when @theatre/studio is imported but studio.initialize() is never called within 5 seconds.

What changed

  • Extracted the initialization warning into a standalone InitWarning class (initWarning.ts) for testability
  • Increased timeout from 100ms → 5s to give frameworks time to set up before warning
  • Changed console.errorconsole.warn since this is a warning, not an error
  • Timer is now properly cleared via clearTimeout() when initialize() is called (previously only checked a boolean flag)
  • Added 5 unit tests covering:
    • Warning emits after timeout if studio not initialized
    • Warning does NOT emit if initialize() is called before timeout
    • Timer is cleared on initialize()
    • Late initialization warning emits if initialize() is called after timeout
    • initialize() is idempotent (returns false on second call)

Behavior

  1. When @theatre/studio is imported, a 5-second timer starts
  2. If studio.initialize() is called before the timer fires, the timer is cleared — no warning
  3. If the timer fires without initialize() being called, a console.warn explains how to fix it
  4. If initialize() is called after the warning, a second message notes the late initialization

Test plan

  • yarn test — all existing tests pass (18 suites, 242 tests)
  • 5 new tests pass covering both initialized and not-initialized paths

Addresses theatre-js#21 — warn when @theatre/studio is imported but
studio.initialize() is not called.

Changes:
- Extract initialization warning logic into InitWarning class for
  testability
- Increase timeout from 100ms to 5s to allow framework setup time
- Use console.warn instead of console.error (it's a warning, not an error)
- Clear the timer when initialize() is called (previously only checked
  a flag)
- Add 5 unit tests covering: warning fires, warning suppressed by
  initialize(), timer cleared, late initialization warning, and
  idempotent initialize()

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
theatre-playground Building Building Preview Aug 12, 2026 10:47am

Request Review

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants