Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the banner not showing again after dismissed by the user if the next message contents are the same #1352

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

tomsb
Copy link
Contributor

@tomsb tomsb commented Aug 7, 2023

This alters already accepted PR #1045 to trigger the banner even if the next message contents did not change.

Explanation:
watch: setting the same value for a primitive type (number, string, boolean...) will not be considered as a value change.
watchEffect: triggers the change even if you set the same value, showing the banner again.

How to reproduce:

  1. Flash a banner with the message "Action successful."
  2. The user acknowledges the banner and clicks on the x button.
  3. Flash another banner with the same message "Action successful."
  4. No banners will be shown again, unless the message contents changes, user manually reloads the page or does a non-Inertia navigation.

@timacdonald timacdonald marked this pull request as draft August 10, 2023 23:04
@timacdonald
Copy link
Member

Hey @tomsb,

Could you show us the minimum code required to reproduce the issue we are trying to fix here?

I've made the following change to a fresh Jetstream install and things seem to work as expected?

// web.php

Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/dashboard', function () {
-        return Inertia::render('Dashboard');
+        return Inertia::render('Dashboard', [
+            'jetstream' => [
+                'flash' => [
+                    'banner' => 'Welcome to Jetstream'
+                ],
+            ],
+        ]);
    })->name('dashboard');
});

The banner continues to reappear after it is dismissed without the need for a manual reload or a non-inertia request.

Screen.Recording.2023-08-11.at.9.11.13.am.mov

@tomsb
Copy link
Contributor Author

tomsb commented Aug 11, 2023

Sure! Minimum code required (using fresh Jetstream install):

// app/Actions/Fortify/UpdateUserProfileInformation.php

public function update(User $user, array $input): void
{
    Validator::make($input, [
        'name' => ['required', 'string', 'max:255'],
        'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
        'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
    ])->validateWithBag('updateProfileInformation');

    if (isset($input['photo'])) {
        $user->updateProfilePhoto($input['photo']);
    }

    if ($input['email'] !== $user->email &&
        $user instanceof MustVerifyEmail) {
        $this->updateVerifiedUser($user, $input);
    } else {
        $user->forceFill([
            'name' => $input['name'],
            'email' => $input['email'],
        ])->save();
    }

+   request()->session()->flash('flash.banner', 'Profile saved.');
+   request()->session()->flash('flash.bannerStyle', 'success');
}

Steps to reproduce:

  1. Open the profile page
  2. Click on the "Save" button (under Profile Information)
  3. Banner with "Profile saved." will appear
  4. Close the banner with an "x"
  5. Click on the same "Save" button again
  6. Banner will not reappear.

@timacdonald
Copy link
Member

Thanks, @tomsb. Just confirmed this one.

@timacdonald timacdonald marked this pull request as ready for review August 14, 2023 01:10
@taylorotwell taylorotwell merged commit 83738ba into laravel:3.x Aug 14, 2023
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.

3 participants