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

Plugin loading order is not deterministic #10441

Closed
khalwat opened this issue Jan 29, 2022 · 3 comments
Closed

Plugin loading order is not deterministic #10441

khalwat opened this issue Jan 29, 2022 · 3 comments
Labels

Comments

@khalwat
Copy link
Contributor

khalwat commented Jan 29, 2022

Currently services/Plugins loads plugins with this query:

            $pluginInfo = $this->_createPluginQuery()
                ->indexBy('handle')
                ->all();

ref: https://github.com/craftcms/cms/blob/develop/src/services/Plugins.php#L198

Unfortunately, this means that plugin loading order is not deterministic; it depends on in what order plugins are installed. This makes it difficult to track down issues such at this one in SEOmatic, because plugins will load in a different order on Site A than Site B:

nystudio107/craft-seomatic#654 (comment)

...where the issue only happens if SEOmatic is installed before Craft Commerce is installed. So obviously an issue on my end that will be fixed, but I think it would make diagnosing issues such as this easier if plugins were always loaded in a deterministic order, just like MacOS kernel extensions and other such things are.

So I propose changing the query to:

            $pluginInfo = $this->_createPluginQuery()
                ->indexBy('handle')
                ->orderBy(['handle' => SORT_ASC])
                ->all();

...so that plugins will always be loaded in a deterministic order, alphabetically by their plugin handle.

While it may seem like it's a breaking change in terms of affecting the loading order of plugins, you're actually making that same breaking change yourself every time you install or uninstall a plugin.

Deterministic loading order across sites is always better than random on a per-site basis, based on a hidden variable (install order)

Related: #3028

@brandonkelly
Copy link
Member

Fixed for the next release!

Now we wait for someone to release “AAA SEO”…

@khalwat
Copy link
Contributor Author

khalwat commented Feb 8, 2022

Yeah, I know, I know re: "AAA SEO" but at least it'll be the same on every install. I'm with @AugustMiller that plugins should be agnostic about loading order, but this will make it easier to debug when something goes wrong.

Thx @brandonkelly !

@brandonkelly
Copy link
Member

3.7.31 is out now with that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants