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

Mingle Laravel Package

ijpatricio/mingle

MingleJS lets you use React or Vue components inside Laravel Livewire apps. It renders a server-side div and mounts the JS component client-side, passing data from PHP and enabling easy server actions via $wire for “islands” of interactivity.

View on GitHub
Deep Wiki
Context7

Integration Approach

Stack Fit

  • Core Stack Alignment:

    • Laravel Livewire: Native integration via @mingle directive, preserving Livewire’s server-driven reactivity and Blade templating.
    • Vue 3/React 16+: Client-side rendering for interactive components, with MingleJS handling the bridge between server-rendered HTML and client-side mounting.
    • Laravel Mix/Vite: Required for bundling and optimizing JS components. Vite is preferred for its faster HMR and modern build optimizations (e.g., ES modules, code-splitting).
    • Filament (Optional): If using Filament, MingleJS can embed Vue/React components within Filament panels or resources, leveraging Filament’s Laravel integration.
  • Tooling Synergy:

    • Alpine.js: Can coexist for lightweight interactivity (e.g., tooltips, modals) where Vue/React is unnecessary.
    • Tailwind CSS: Works seamlessly with both Livewire and Vue/React components for consistent styling.
    • Laravel Echo/Pusher: For real-time features (e.g., notifications), pair with Vue/React components mounted via MingleJS.
    • Pinia (Vue) / Redux (React): For state management across MingleJS components, especially if sharing data between multiple islands.
  • Architectural Patterns:

    • Island Architecture: MingleJS enforces this by default, rendering JS components as self-contained "islands" within Livewire’s server-rendered pages.
    • Progressive Enhancement: Non-JS users (or users with JS disabled) see functional Livewire content, with enhanced interactivity added client-side.
    • Micro-Frontends: Treat each MingleJS component as a micro-frontend, enabling independent development cycles for Vue/React and Livewire teams.

Migration Path

  1. Pilot Phase (Low Risk):

    • Select a Non-Critical Component: Choose a Livewire component with moderate complexity (e.g., a settings panel, a filter sidebar, or a data table) to test MingleJS.
    • Refactor to MingleJS:
      • Replace static HTML/Alpine.js logic with a Vue/React component.
      • Use Livewire to pass initial props/data to the JS component via @mingle directive.
      • Example:
        @mingle('TodoList', ['todos' => $todos])
        
      • Mount the component in a dedicated JS file (e.g., resources/js/components/TodoList.vue).
    • Validate:
      • Test hydration, state synchronization, and edge cases (e.g., rapid prop updates).
      • Measure performance impact (TTFB, LCP, bundle size).
  2. Incremental Rollout:

    • Component-by-Component: Gradually replace Livewire components with MingleJS-enhanced versions, prioritizing high-impact, interactive features.
    • Feature Flags: Use Laravel’s feature flags or environment variables to toggle MingleJS components in production, allowing for canary releases.
    • CI/CD Integration:
      • Add tests for MingleJS components (see Testing Strategy below).
      • Configure GitHub Actions or Laravel Forge to rebuild assets when JS dependencies update.
  3. Full Adoption:

    • Standardize Patterns: Document conventions for:
      • Prop passing between Livewire and JS components.
      • Error handling and fallbacks.
      • Styling and theming consistency.
    • Team Training: Conduct workshops on:
      • MingleJS’s internals (e.g., how data flows between server and client).
      • Vue/React best practices for Laravel integration.
      • Debugging hybrid stacks.
    • Monitoring: Implement observability for MingleJS components (e.g., track mount failures, hydration time).

Compatibility

  • Laravel Versions:
    • Tested with Laravel 9+ (check MingleJS docs for exact compatibility).
    • Ensure compatibility with the project’s Laravel and Livewire versions (e.g., Livewire 2.x vs. 3.x).
  • Vue/React Versions:
    • Supports Vue 3 and React 16+. Align with the project’s existing JS ecosystem.
    • For Vue, ensure @vue/compiler-sfc is compatible with Laravel Mix/Vite.
  • Build Tools:
    • Laravel Mix: Works out-of-the-box but may require configuration for code-splitting.
    • Vite: Recommended for modern projects. Configure vite.config.js to resolve MingleJS components:
      import { defineConfig } from 'vite';
      import laravel from 'laravel-vite-plugin';
      import vue from '@vitejs/plugin-vue';
      
      export default defineConfig({
        plugins: [
          laravel({
            input: ['resources/js/app.js', 'resources/js/components/**/*.vue'],
            refresh: true,
          }),
          vue(),
        ],
      });
      
  • Filament Integration:
    • For Filament projects, use MingleJS within custom panels or resources:
      // In a Filament resource
      public static function form(Form $form): Form {
          return $form
              ->schema([
                  // ...
                  MingleJS::make('CustomComponent', [
                      'data' => $this->getCustomData(),
                  ]),
              ]);
      }
      

Sequencing

  1. Prerequisites:

    • Ensure Laravel and Livewire are up-to-date.
    • Set up Laravel Mix/Vite for JS bundling (if not already configured).
    • Install Vue/React and their dev dependencies (e.g., @vitejs/plugin-vue, @vitejs/plugin-react).
    • Install MingleJS:
      composer require ijpatricio/mingle
      npm install @vue/compiler-sfc vue react react-dom  # or equivalent for React
      
  2. Development Workflow:

    • Livewire Component: Create or modify a Livewire component to include the @mingle directive.
    • JS Component: Develop the Vue/React component in resources/js/components/.
    • Data Flow:
      • Pass data from Livewire to JS via @mingle props.
      • Use Livewire’s $wire object in JS for server actions (e.g., $wire.addTodo(todo)).
    • Example Workflow:
      sequenceDiagram
          participant Livewire
          participant Blade
          participant MingleJS
          participant Vue
          participant Server
      
          Livewire->>Blade: Render @mingle('TodoList', ['todos' => $todos])
          Blade->>MingleJS: Inject div with data-attributes
          MingleJS->>Vue: Mount TodoList.vue
          Vue->>Server: Emit $wire.addTodo(todo)
          Server->>Livewire: Handle server action
          Livewire->>Vue: Update props via Livewire events
      
  3. Testing and Validation:

    • Unit Tests: Test Vue/React components in isolation (e.g., using @testing-library/vue).
    • Integration Tests: Test Livewire + MingleJS interactions (e.g., prop updates, server actions).
    • E2E Tests: Use Cypress/Playwright to validate full user flows, including JS hydration.
    • Performance Tests: Measure bundle size, hydration time, and TTFB with Lighthouse or custom scripts.
  4. Deployment:

    • Staging: Deploy MingleJS components to staging for QA testing.
    • Production: Use feature flags or environment variables to enable MingleJS gradually.
    • Rollback Plan: Ensure Livewire fallbacks are in place for failed JS mounts.

Operational Impact

Maintenance

  • Dependency Management:

    • Pros: MingleJS abstracts much of the complexity of integrating Vue/React with Livewire, reducing boilerplate.
    • Cons: New dependencies (Vue/React) increase maintenance overhead. Monitor for:
      • Security updates (e.g., Vue/React CVEs).
      • Breaking changes in Laravel/Livewire that may affect MingleJS.
    • Mitigation:
      • Use dependabot or laravel-dependency-updater to track updates.
      • Pin versions in composer.json and package.json to avoid unexpected updates.
      • Example composer.json:
        "require": {
            "ijpatricio/mingle": "^1.0",
            "laravel/livewire": "^3.0"
        }
        
  • Component Lifecycle:

    • Isolation: MingleJS components are self-contained, reducing ripple effects when updating Livewire or JS logic.
    • Documentation: Maintain a runbook for:
      • How to add/update MingleJS components.
      • Prop schemas and data flow.
      • Debugging common issues (e.g., hydration mismatches).
    • Deprecation: Plan for gradual replacement of MingleJS components if the app migrates to a full SPA (e.g., Inertia.js).

Support

  • Debugging Challenges:
    • Hybrid Stack Issues: Errors may originate in:
      • Livewire (server-side logic).
      • MingleJS (mounting/hydration).
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor