Documentation

Plugin Lifecycle

Understanding how plugins are loaded, initialized, and executed in Frame-Master.

🔄 Lifecycle Overview

Plugins move through distinct phases:

  1. Initialization — Plugins loaded, sorted by priority, requirements validated
  2. Context — createContext seeds getGlobalPluginContext
  3. Server Startup — serverStart hooks execute, then Bun.serve, then serverReady
  4. Request Processing — Router hooks handle each HTTP request
  5. Shutdown / reload — serverStop on the current generation (reverse priority)
  6. Build Process — Build hooks customize compilation

📋 Execution Flow

// Server Start
createContext → serverStart.main → serverStart.dev_main → Bun.serve → serverReady
 
// Config reload
serverStop(old plugins) → HTTP stop → reinit → onConfigReload → Bun.serve → serverReady
 
// Process signal (dev/start)
serverStop(reason: signal) → HTTP stop(true) → process.exit
 
// Each Request
before_request → request → after_request → html_rewrite → global_value_injection
 
// Build
buildConfig → beforeBuild → [Bun Build] → afterBuild

📊 Priority Order

Lower priority numbers execute first.

export default defineConfig({
  plugins: [
    logging(), // priority: 100 → runs last
    reactSSR(), // priority: 50  → runs mid
    session(), // priority: 10  → runs second
    auth(), // priority: 0   → runs first
  ],
}); // Order: auth → session → reactSSR → logging

Recommended ranges:

  • Auth: 0–10
  • Session/DB: 10–30
  • Processing: 30–60
  • Logging: 80–100

✨ Best Practices

  • ⚡ Keep hooks lightweight; push heavy work to serverStart
  • 🔒 Handle errors with try-catch; fail gracefully

🎯 Next Steps