Skip to content

[Feat] Inertia Context Shifting#1094

Open
RichardAnderson wants to merge 3 commits into
vitodeploy:4.xfrom
RichardAnderson:feat/context-shifting
Open

[Feat] Inertia Context Shifting#1094
RichardAnderson wants to merge 3 commits into
vitodeploy:4.xfrom
RichardAnderson:feat/context-shifting

Conversation

@RichardAnderson
Copy link
Copy Markdown
Member

This pull request introduces a new centralized bootstrap system to manage and cache application configuration and public key data, as well as a similar system for Ziggy route data. It refactors how this information is provided to the frontend, improving cache invalidation and real-time update mechanisms, especially around plugin lifecycle events. Additionally, it simplifies and modernizes how configuration data is accessed in React components and cleans up some controller and middleware logic.

Vito's Inertia responses were shipping ~120 KB+ of mostly-static shared data on every visit: the full Ziggy route table (~70 KB), the provider/service/site-type catalogue (~35 KB), the SSH public-key text, and an eager-loaded site-with-SSL collection on every server-route request. This PR cuts each of those pathways down to the minimum and adds a small invalidation channel so admin plugin toggles still propagate instantly to other users.

Result: typical Inertia XHR responses are now ~1–3 KB shared + page data (down from ~120 KB+). HTML first-loads no longer embed the route table. The custom proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; overrides in nginx are no longer needed.

Centralized Bootstrap and Ziggy Route Management:

  • Introduced GetBootstrap and GetZiggyRoutes action classes to encapsulate, cache, and version application configuration, public key text, and Ziggy route data, with cache invalidation and versioning methods for both. (app/Actions/Bootstrap/GetBootstrap.php, app/Actions/Ziggy/GetZiggyRoutes.php)
  • Added new controllers for serving bootstrap data (BootstrapController) and Ziggy routes (ZiggyRoutesController), exposing these via dedicated endpoints. (app/Http/Controllers/BootstrapController.php, app/Http/Controllers/ZiggyRoutesController.php)

Plugin Lifecycle and Real-Time Updates:

  • Updated plugin install/enable/disable/uninstall actions to invalidate the bootstrap cache, recompute the version, and dispatch a real-time socket event to notify clients of bootstrap changes. (app/Actions/Plugins/InstallPlugin.php, app/Actions/Plugins/EnablePlugin.php, app/Actions/Plugins/DisablePlugin.php, app/Actions/Plugins/UninstallPlugin.php)
  • Enhanced WebSocket event handling to allow broadcasting events to all connected clients, not just by project. (app/WebSocket/EventsHandler.php, app/Console/Commands/WebSocketServeCommand.php)

Frontend Integration and Refactoring:

  • Introduced a bootstrap-store for React to centrally manage and hydrate configuration and public key data, replacing scattered access via Inertia's shared props. (resources/js/app.tsx, resources/js/components/color-select.tsx, resources/js/components/user-menu-content.tsx)
  • Updated components (e.g., ColorSelect, UserMenuContent) to use the new store for configuration data and ensure proper clearing of bootstrap state on logout.

Middleware and Controller Cleanup:

  • Refactored HandleInertiaRequests middleware to remove direct configuration and public key data from shared props, instead providing only the bootstrap version and CSRF token. Also removed server sites data from shared props. (app/Http/Middleware/HandleInertiaRequests.php)
  • Removed unused server log resource from ApplicationController. (app/Http/Controllers/ApplicationController.php)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Replaces ~120 KB of shared Inertia data (Ziggy route table, provider/service catalogue, public-key text, eager-loaded sites) with a small bootstrap_version token plus on-demand endpoints, and introduces a client-side bootstrap-store (Zustand) with localStorage caching. A websocket bootstrap.invalidated event from plugin lifecycle Actions keeps connected clients in sync, and the route catalogue is now served as a cacheable /ziggy/{version}.js script.

Changes:

  • New GetBootstrap / GetZiggyRoutes Actions with versioning + cache invalidation, plus BootstrapController and ZiggyRoutesController endpoints.
  • Plugin install/enable/disable/uninstall Actions forget the bootstrap version and broadcast bootstrap.invalidated to all clients (new EventsHandler::broadcastToAll and project_id=0 support in WebSocketServeCommand).
  • HandleInertiaRequests drops configs, public_key_text, server_sites, and unconditional ziggy; React components migrate from usePage().props.configs to useConfigs() from the new store; Layout gates rendering on bootstrap readiness and exposes an error/retry state.

Reviewed changes

Copilot reviewed 33 out of 34 changed files in this pull request and generated no comments.

Show a summary per file
File Description
app/Actions/Bootstrap/GetBootstrap.php New Action that assembles configs + public key text and a stable version hash.
app/Actions/Ziggy/GetZiggyRoutes.php Builds, caches, versions, and serves the Ziggy route script.
app/Actions/Plugins/{Install,Enable,Disable,Uninstall}Plugin.php Invalidate bootstrap version and broadcast bootstrap.invalidated.
app/Http/Controllers/BootstrapController.php Auth-protected JSON endpoint returning bootstrap payload.
app/Http/Controllers/ZiggyRoutesController.php Public, immutable-cached JS endpoint serving Ziggy routes.
app/Http/Controllers/ApplicationController.php Removes now-unused logs prop.
app/Http/Middleware/HandleInertiaRequests.php Trims shared props; ships only bootstrap_version (+ ziggy when SSR).
app/WebSocket/EventsHandler.php Adds broadcastToAll to fan out to every connection.
app/Console/Commands/WebSocketServeCommand.php Treats project_id=0 as a global broadcast.
resources/views/app.blade.php Replaces @routes with cached /ziggy/{version}.js script tag.
resources/js/app.tsx Hydrates bootstrap store from localStorage on boot.
resources/js/stores/bootstrap-store.ts New Zustand store: hydrate / fetch / sync / clear with localStorage.
resources/js/layouts/app/layout.tsx Syncs bootstrap with server version, listens for invalidation, gates children and shows error/retry UI.
resources/js/components/{color-select,user-menu-content}.tsx Use the new store; clear it on logout.
resources/js/pages/.../*.tsx (many) Migrate from page.props.configs / public_key_text to useConfigs() / usePublicKeyText().
resources/js/pages/application/index.tsx Replaces the inline log DataTable with the shared Logs component (drops logs prop / realtime hook).
resources/js/pages/server-logs/components/instant-logs.tsx Tightens typing of the query response and consolidates the two refetch effects.
resources/js/pages/servers/components/create-server.tsx Adds toast on clipboard rejection; reads public key from the store.
resources/js/types/index.d.ts Drops configs / public_key_text / server_sites and adds bootstrap_version; ziggy now optional.

@RichardAnderson
Copy link
Copy Markdown
Member Author

No comments from Copilot? Wow... thats a first!

@RichardAnderson RichardAnderson marked this pull request as ready for review May 17, 2026 08:50
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