Dynamic supervisor for JavaScript runtime processes and file watching.
This module manages the lifecycle of JavaScript runtime processes (Bun/Deno) and coordinates file watching for hot reloading in development mode.
Features
- Runtime Management: Supervises JavaScript runtime processes
- Hot Reloading: Automatic component rebuilding in development
- File Watching: Monitors component directory changes with throttling
- Graceful Restart: Handles runtime failures and restarts
- Development Mode: Enhanced developer experience with live reloading
Runtime Lifecycle
Development Mode
- Starts file watcher for component directory
- Monitors file changes with 3-second throttle
- Triggers automatic runtime restart on component changes
- Provides hot reloading for seamless development
Production Mode
- Starts optimized runtime processes
- No file watching (minimal overhead)
- Uses pre-bundled components for performance
Supported Runtimes
- Bun (
Phoenix.ReactServer.Runtime.Bun): Fast JavaScript runtime - Deno (
Phoenix.ReactServer.Runtime.Deno): Secure runtime with npm support
Configuration
Runtime behavior is controlled via application configuration:
config :phoenix_react_ng, Phoenix.ReactServer.Runtime.Bun,
env: :dev, # :dev or :prod
port: 5225,
component_base: "/path/to/components"Performance Considerations
- Development mode incurs file watching overhead
- Throttling prevents excessive rebuilds during rapid changes
- Runtime processes are isolated for stability
- Automatic restart ensures reliability
Summary
Types
Component name
Rendered HTML output
Rendering method
File system path
Render response
Runtime configuration
Runtime start arguments
Runtime state structure
Callbacks
Returns runtime configuration.
Renders a component using the specified method.
Starts the runtime with given arguments.
Starts a file watcher for the component directory.
Functions
Returns a specification to start this module under a supervisor.
Callback implementation for DynamicSupervisor.init/1.
Types
@type component() :: String.t()
Component name
@type html() :: String.t()
Rendered HTML output
@type method() ::
:render_to_readable_stream | :render_to_string | :render_to_static_markup
Rendering method
@type path() :: Path.t()
File system path
Render response
@type runtime_config() :: keyword()
Runtime configuration
Runtime start arguments
@type t() :: %Phoenix.ReactServer.Runtime{ cd: Path.t(), component_base: Path.t(), render_timeout: timeout(), runtime_port: port(), server_js: Path.t() }
Runtime state structure
Callbacks
@callback config() :: runtime_config()
Returns runtime configuration.
@callback get_rendered_component(method(), component(), map(), t()) :: render_response()
Renders a component using the specified method.
@callback start(start_args()) :: port()
Starts the runtime with given arguments.
Returns a port that can be used to communicate with the runtime process.
Starts a file watcher for the component directory.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Callback implementation for DynamicSupervisor.init/1.