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

New buildMailable Implementation Fails to Invoke build Method, Breaking Edit and Preview Functionality #241

Open
enact-on opened this issue Feb 25, 2024 · 6 comments
Labels
bug Something isn't working Review Needed

Comments

@enact-on
Copy link

Introduction:

We have identified a critical regression after updating from version 2.3.0 to 4.0.3 in our Laravel application. The new implementation of the buildMailable method fails to invoke the build method on mailable instances, which is essential for setting up markdown views in our mailables. This oversight has significantly impacted our ability to edit and preview mailables.

Problem Description:

In the previous version (2.3.0), the buildMailable function properly invoked the build method on mailable instances, ensuring all necessary attributes, including markdown views, were correctly set for further processing. However, in the updated version (4.0.3), the method's logic change no longer guarantees the build method's invocation for every mailable instance. Our application relies on the build method to set the markdown property of mailables, which is crucial for rendering the email content correctly. This change has resulted in the markdown property not being set, thereby breaking the edit and preview functionality of mailables in our application.

Impact:

This regression disrupts our email management workflow, as the inability to set markdown views in the build method means we cannot accurately render or modify email content. This functionality is critical for our application's operation and user experience.

Code Comparison:

Old Version (2.3.0): Ensured the build method was called, allowing the markdown view to be set along with other mailable attributes.

public static function buildMailable($instance, $type = 'call')
    {
        if ($type == 'call') {
            if (! is_null(self::handleMailableViewDataArgs($instance))) {
                return Container::getInstance()->call([self::handleMailableViewDataArgs($instance), 'build']);
            }

            return Container::getInstance()->call([new $instance, 'build']);
        }

        return Container::getInstance()->make($instance);
    }
    

New Version (4.0.3): Does not consistently invoke the build method, especially in scenarios where the markdown view setting is integral to the mailable's functionality.

public static function buildMailable($instance, $type = 'call')
    {
        $method = method_exists($instance, 'build') ? 'build' : 'content';

        if ($type === 'call') {
            if (self::handleMailableViewDataArgs($instance) !== null) {
                return self::handleMailableViewDataArgs($instance);
            }

            if ($method == 'content') {
                /** @var \Illuminate\Mail\Mailable */
                $class = new $instance;
                $class->view(app()->call([new $instance, 'content'])->view);

                return $class;
            }

            return app()->call([new $instance, $method]);
        }

        return app()->make($instance);
    }
@enact-on enact-on added bug Something isn't working Review Needed labels Feb 25, 2024
@enact-on
Copy link
Author

return app()->call([self::handleMailableViewDataArgs($instance), 'build']);

Looks in v3 also has build method in it. But in v4 its not calling it anymore.

@ReeceM
Copy link
Collaborator

ReeceM commented Feb 25, 2024

Hi @enact-on, sorry there is a bug that is breaking your app. What version are you using?

@enact-on
Copy link
Author

@ReeceM
As mentioned above, currently we are using the latest version because we have moved to Laravel 10

But v2.x and v3.x code looks good.

Change occurred in v4.x , i've shared the code change in original comment.

@enact-on
Copy link
Author

enact-on commented Mar 1, 2024

Hi @ReeceM

Did you get to review this? "build" method is no longed called in v4.

This is unexpected change in v4, its breaking change for our use case.

@ReeceM
Copy link
Collaborator

ReeceM commented Mar 1, 2024

@enact-on Unfortunately I work in the week and have commitments on some of the other days.

What I just want to ask do your markdown mails work with the latest version of laravel tho, not with the package?

@enact-on
Copy link
Author

enact-on commented Mar 1, 2024

Yes , our mailables works fine in all Laravel v7,8,9,10.

Because Mailable, the build method gets called by Laravel so it works fine.
In case of package v4, build method isn't called, hence it can't preview or edit template.

Hope this answers.

Thanks for your support, totally understandable your commitment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Review Needed
Projects
None yet
Development

No branches or pull requests

2 participants