protonemedia / laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
https://splade.dev
MIT License
1.47k stars 112 forks source link

X-Splade-Rehydrate loads the wrong part #548

Open Lioxen opened 9 months ago

Lioxen commented 9 months ago

Description:

I have on my site different x-splade-rehydrate with different names (on="name1", on="name2" ...) but it loads every time the content of the first x-splade-rehydrate even if I call the second one (push an event e.g. @success="$splade.emit('name2')")

Steps To Reproduce Issue:

  1. Add new routes in your routes file (web.php)

    Route::view('/test', 'test');
    Route::post('/test', function (Request $request) {
                session()->push('data.members',$request->get('name'));
            return redirect()->back();
        });
    Route::view('/testmodal', 'testmodal');
    Route::post('/testmodal', function (Request $request) {
                session()->push('data.users',$request->get('user'));
            return redirect()->back();
        });
  2. Add 2 views to call test.blade.php

    
    <x-splade-rehydrate on="team-member-added">
    @if(session()->has('data.members'))
    <ul>
        @foreach(session()->get('data.members') as $member)
            <li>{{ $member }}</li>
        @endforeach
    </ul>
    @endif
    </x-splade-rehydrate>

<x-splade-form action="/test" stay @success="$splade.emit('team-member-added')">

<x-splade-submit />

Create new user
testmodal.blade.php
@if(session()->has('data.users'))
    @foreach(session()->get('data.users') as $user)
  • {{ $user }}
  • @endforeach
@endif

Create new user



4. Call the test.blade.php (/test) and insert some names
5. Click the 'Create new user' link to open the modal form
6. Insert a name (should be a different name :) and submit the form
7. Now you see the list of the names you inserted on the first form
8. Reopen the modal window and you see the name you inserted on the second form (just to see, it was saved)