Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ux Turbo Laravel Package

symfony/ux-turbo

Symfony UX Turbo integrates Hotwire Turbo into Symfony apps, enabling faster navigation, Turbo Frames/Streams updates, and smoother UX with minimal custom JavaScript. Includes Stimulus integration and tools to progressively enhance pages and forms.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony-Native Integration: Seamlessly integrates with Symfony’s core components (Twig, Doctrine, Mercure) without requiring a full frontend overhaul. Leverages Symfony’s dependency injection, routing, and templating systems, reducing architectural friction.
  • Hybrid Architecture Support: Enables a progressive enhancement approach, allowing gradual adoption of Turbo features (e.g., Turbo Frames for isolated components before full-page transitions).
  • Mercure Synergy: Tight coupling with Symfony Mercure enables real-time updates via Server-Sent Events (SSE), bridging the gap between Turbo’s client-side transitions and server-driven reactivity.
  • Twig-Centric: Extends Twig with custom components (<twig:Turbo:Stream>, <twig:Turbo:Frame>) and functions (turbo_stream_from(), turbo_is_frame_request()), aligning with Symfony’s templating philosophy.

Integration Feasibility

  • Low Barrier to Entry: Requires minimal frontend changes—Turbo works with vanilla JavaScript or existing asset pipelines (e.g., StimulusBundle). No need for Webpack/ESBuild if using the default setup.
  • Backend-First: Primarily a backend library; frontend changes are declarative (e.g., adding data-turbo-* attributes to HTML elements). Ideal for teams with stronger PHP than JavaScript expertise.
  • Symfony Version Lock: Hard dependency on Symfony 7.4+ and PHP 8.4 (as of v3.0). Requires upgrading if using older versions, but the migration path is straightforward (see Integration Approach).
  • Mercure Dependency: For real-time features, requires symfony/mercure-bundle (v0.4.1+), adding another moving part but enabling powerful use cases like live notifications.

Technical Risk

  • Breaking Changes: Recent versions (v3.0+) have removed backward compatibility layers (e.g., deprecated TurboStreamListenRendererInterface). Teams using older Symfony UX packages (e.g., symfony/ux-turbo-mercure) must migrate to mercure-bundle.
  • JavaScript Module System: v2.13+ uses ES Modules (type: module in package.json), which may require adjustments to existing asset pipelines or browser support considerations.
  • Turbo’s Limitations: Not a full SPA replacement—complex client-side state management (e.g., Redux) or highly dynamic UIs may still require complementary tools (e.g., Alpine.js, HTMX).
  • SEO/Progressive Enhancement: While Turbo supports fallback routes, ensuring accessibility and SEO for disabled JavaScript requires careful implementation (e.g., testing with data-turbo="false").

Key Questions

  1. Symfony Version Compatibility:

    • Are we on Symfony 7.4+ and PHP 8.4+? If not, what’s the upgrade path and risk?
    • How will we handle deprecated APIs (e.g., turbo_stream_listen()) in existing code?
  2. Frontend Strategy:

    • Do we need to adopt ES Modules (type: module) for Turbo’s JS, or can we use a CDN?
    • How will we integrate Turbo with existing JavaScript (e.g., Stimulus, jQuery)?
  3. Real-Time Requirements:

    • Do we need Mercure for live updates, or can we start with Turbo’s built-in EventSource?
    • How will we secure Mercure topics (e.g., authentication, authorization)?
  4. Performance:

    • What’s our baseline for page load times? Could Turbo’s JS overhead impact performance?
    • How will we measure the impact of Turbo Frames on server load (e.g., partial renders)?
  5. Team Skills:

    • Does the team have experience with Turbo/Hotwire or similar tools (e.g., HTMX)?
    • How will we train developers on Turbo’s conventions (e.g., data-turbo-* attributes)?
  6. Fallbacks:

    • How will we handle users without JavaScript (e.g., feature detection, graceful degradation)?
    • Are there critical paths that must work without Turbo?
  7. Long-Term Maintenance:

    • How will we monitor Turbo’s compatibility with future Symfony/Stimulus updates?
    • What’s our rollback plan if Turbo introduces breaking changes?

Integration Approach

Stack Fit

  • Symfony Core: Fully compatible with Symfony 7.4+ (recommended) and 6.4+ (with some deprecations). Leverages:
    • Twig: Custom components and functions for streaming responses.
    • Doctrine: Broadcasts entity changes for real-time updates.
    • Mercure: Optional but powerful for live collaboration (e.g., chat, live edits).
    • StimulusBundle: Replaces WebpackEncore for asset management (v2.9+).
  • Frontend:
    • Vanilla JS: Turbo works out-of-the-box with no build step.
    • Stimulus: For enhanced interactivity (e.g., modals, transitions).
    • Alpine.js/HTMX: Can coexist for more complex UIs.
  • Database: Doctrine ORM for broadcasting entity changes (e.g., @Broadcast attribute).

Migration Path

  1. Assessment Phase:

    • Audit existing routes, controllers, and templates for Turbo compatibility.
    • Identify high-impact use cases (e.g., forms, modals, infinite scroll).
    • Test with a non-critical feature (e.g., a "quick view" modal).
  2. Setup:

    composer require symfony/ux-turbo symfony/mercure-bundle  # if needed
    
    • Configure symfony/ux-turbo in config/bundles.php:
      Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
      Symfony\UX\MercureBundle\MercureBundle::class => ['all' => true],
      
    • Update assets/controllers.json to enable the mercure-turbo-stream controller (if using Mercure).
  3. Incremental Adoption:

    • Phase 1: Turbo Frames
      • Replace static includes with <turbo-frame> tags.
      • Example: Convert a "user profile" partial into a frame:
        <turbo-frame id="user_profile">
            {% include 'user/profile.html.twig' %}
        </turbo-frame>
        
      • Update the controller to return a TurboStreamResponse:
        use Symfony\UX\Turbo\TurboBundle;
        
        public function updateProfile(Request $request): Response
        {
            // ... update logic
            if (TurboBundle::STREAM_FORMAT === $request->getPreferredFormat()) {
                return $this->render('user/_profile.stream.html.twig', ['user' => $user]);
            }
            return $this->render('user/profile.html.twig', ['user' => $user]);
        }
        
    • Phase 2: Progressive Enhancement
      • Add data-turbo attributes to links/forms:
        <a href="/posts/1" data-turbo="true">View Post</a>
        <form data-turbo="true">...</form>
        
    • Phase 3: Real-Time Updates (Optional)
      • Integrate Mercure for live broadcasts:
        <turbo-mercure-stream-source src="{{ path('mercure') }}" topics="{{ mercureHubUrl }}topic/posts">
        
        • Annotate entities with @Broadcast:
          #[Broadcast]
          class Post {}
          
  4. Testing:

    • Verify Turbo Frames render correctly with Accept: text/vnd.turbo-stream.html.
    • Test JavaScript-disabled fallbacks (e.g., data-turbo="false").
    • Monitor Mercure topic subscriptions for real-time updates.

Compatibility

  • Symfony Ecosystem:
    • Works with Symfony’s asset mapper (v2.9+), making it compatible with modern asset management.
    • Integrates with Symfony Security for authenticated Turbo Streams.
  • Third-Party:
    • Mercure: Requires symfony/mercure-bundle (v0.4.1+) for real-time features.
    • Stimulus: Uses StimulusBundle (v2.9+) for asset compilation.
    • Doctrine: Broadcasts entity changes via Doctrine listeners.
  • Browser Support: Turbo supports all modern browsers (Chrome, Firefox, Safari, Edge) and degrades gracefully for older ones.

Sequencing

  1. Prerequisites:
    • Upgrade Symfony to 7.4+ and PHP to 8.4 (if not already).
    • Migrate from symfony/ux-turbo-mercure to mercure-bundle (if applicable).
  2. Core Integration:
    • Install symfony/ux-turbo and configure bundles.
    • Set up asset pipeline (StimulusBundle).
  3. Feature Rollout:
    • Start with Turbo Frames for isolated components.
    • Add progressive enhancement to links/forms.
    • Implement Mercure for real-time features (last step).
  4. Optimization:
    • Cache Turbo Stream responses.
    • Monitor performance (e.g
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php