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

Use a scoped singleton to support Laravel Octane #36

Merged
merged 1 commit into from
May 3, 2024

Conversation

benbjurstrom
Copy link
Contributor

Using this package with Laravel Octane causes any values that aren't explicitly set on the current page to be filled with data from other pages that were populated on prior requests.

I believe the fix is to register the SEOManager as a scoped singleton in the SEOServiceProvider. Here's the relevant section of the docs:

Binding Scoped Singletons
The scoped method binds a class or interface into the container that should only be resolved one time within a given Laravel request / job lifecycle. While this method is similar to the singleton method, instances registered using the scoped method will be flushed whenever the Laravel application starts a new "lifecycle", such as when a Laravel Octane worker processes a new request or when a Laravel queue worker processes a new job

closes #35

@stancl
Copy link
Member

stancl commented May 3, 2024

Can you confirm if making this change fixes the Octane issue for you?

@benbjurstrom
Copy link
Contributor Author

Can you confirm if making this change fixes the Octane issue for you?

It appears to. I pushed my fork to a production site running octane earlier today and am no longer seeing data leaking from other routes.

I did have to make one other change on the application side. Since octane only executes the register and boot methods of service providers when the request worker initially boots, I had to move my default definitions from the AppServiceProvider to a middleware.

Other then that everything seems to be working correctly.

@stancl
Copy link
Member

stancl commented May 3, 2024

Thanks for the confirmation. The change does seem to make sense, since the data being stored on the singleton is request-specific. Thanks for the PR!

@stancl stancl merged commit 76d0f9e into archtechx:master May 3, 2024
4 checks passed
@stancl stancl changed the title Update SEOServiceProvider.php Use a scoped singleton to support Laravel Octane May 3, 2024
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.

Laravel Octane - values leaking from prior requests
2 participants