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: Prevent view caching for blade directive #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

saibotk
Copy link

@saibotk saibotk commented Mar 23, 2023

This reintroduces similar behavior as Ziggy implements.
When generating the Blade output the code was automatically cached by
Laravels view system and thus always needed an php artisan view:clear when
introducing new routes and using the blade directive.

This now acts the same as Ziggy does. Please note, that Ziggy once
did also cache the view but returned to this approach, as it breaks
in certain scenarios and has no impactful performance impact:
See tighten/ziggy#349

saibotk added 2 commits March 23, 2023 16:55
This reintroduces similar behaviour as Ziggy implements.
When generating the Blade output the code was automatically cached by
Laravels view system and thus always needed an `php artisan view:clear` when
introducing new routes and using the blade directive.

This now acts the same as Ziggy does. Please note, that Ziggy once
did also cache the view but returned to this apporach, as it breaks
in certain scenarios and has no impactful performance impact:
See tighten/ziggy#349
@pedroborges
Copy link

We are also running into this issue. I would love to see this PR merged 🤞

@mxmtsk
Copy link

mxmtsk commented Jun 2, 2024

Want to push for this to be merged as well, since this package as it is currently doesn't work in a multi-tenant, multi-domain application, since the url property is cached too, leading to CORS errors and requesting to wrong domains altogether.

For everyone having the same issue, to overcome this, before it is merged, I just created a custom directive in AppServiceProvider based on your fix:

    /**
     * Register any application services.
     */
    public function register(): void
    {
        Blade::directive('uncachedtrail', fn () => "<?php echo app('" . TrailBladeGenerator::class . "')::generate(); ?>");
    }

Thank you for this!

@saibotk
Copy link
Author

saibotk commented Jun 2, 2024

You can at this point also go back to ziggy which also has types being generated now

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