Phoenix.ReactServer.Runtime.FileWatcher (Phoenix.ReactServer NG v0.8.4)

Copy Markdown View Source

File system watcher for React components in development.

This module monitors the component directory for changes and triggers automatic rebuilding of the server bundle when components are modified. It implements throttling to prevent excessive rebuilds during rapid file changes.

Features

  • Real-time file system monitoring
  • Throttled rebuilds (3-second delay)
  • Automatic component bundle regeneration
  • Integration with runtime processes

Configuration

The file watcher is automatically started in development mode when the runtime environment is set to :dev.

Requirements

  • inotify-tools must be installed on Linux systems
  • File system events are monitored via the file_system library

Throttling

File changes are throttled to prevent excessive rebuilds:

  • Default throttle time: 3 seconds
  • Only the last change in a burst triggers a rebuild
  • Updates are debounced to ensure file writes complete

Events Monitored

  • File modifications
  • File creation
  • File deletion
  • Directory changes

Summary

Functions

Returns a specification to start this module under a supervisor.

Sets the reference to the runtime process.

Starts the file watcher server.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

set_ref(ref)

@spec set_ref(pid() | reference()) :: :ok

Sets the reference to the runtime process.

Parameters

  • ref - The runtime process PID or reference

Used by the runtime to register itself for file change notifications.

start_link(args)

@spec start_link(keyword()) :: GenServer.on_start()

Starts the file watcher server.

Parameters

  • args - Keyword list containing:
    • :path - Directory path to watch (required)
    • :ref - Runtime process reference (optional)

Returns

  • {:ok, pid} - File watcher started successfully
  • {:error, reason} - Failed to start file watcher