apache / apache/grails-core

layouts in plugins searched in wrong order

Open
#13,114 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Expected Behavior

Let's say I have a grails app, that's working. Great. But then let's say I convert that app to a plugin for use in other apps. It probably won't work, because grails seems to search for layouts in plugins randomly. So let's say your main app doesn't have a layouts/main.gsp, so you're expecting that when you call a web page in your plugin, the plugin should pick up its own layouts/main.gsp, but it doesn't. Instead it seems to pick up a layouts/main.gsp from a random plugin, which is highly likely to be the boilerplate "Welcome to grails" crap, that a lot of plugin writers have just left lying around in their code.

Now you might say, well don't call your layout "main", which is fair, however:

1) We had a situation where it was working fine running as a jar, but not running correctly in Tomcat, seemingly because in one case it randomly picked correctly, and the other time it randomly did not pick correctly. This took an inordinate amount of effort and debugging to try and come to terms with what is going on.

2) People just go with the flow generally, which means there's a lot of plugins out there using main.gsp as their layout, because the template code does that. That means people are releasing plugins that may work for them, but may not work for you.

3) If you call it something else, it still might conflict with another plugin.

I would suggest that the correct order to search for layouts is (1) in the same plugin as the view (2) in the main application, (3) maybe alphabetically by plugin, or some other deterministic, albeit not very interesting order. Or even better, be able to specify a search order.

I realise a case could be made for swapping (1) and (2) above, and that's kinda the current way it works, but I would suggest that the order above will lead to the least unpleasant surprises, which is to search first in view's plugin, but there should be a config item so you can do it the other way.

It also wouldn't hurt if this report https://github.com/grails/grails-core/issues/10110 was implemented, and the template code specified what layout to apply.

### Actual Behaviour

layout seems to be searched for randomly in plugins.

### Steps To Reproduce

1. create plugin that has views and main.gsp layout.
2. embed plugin into top level grails app.
3. include a bunch of other plugins for good measure.
4. run the app and look at one of the views. There's a good chance it will pick up a different main.gsp layout than the one in the plugin that it relates to.

### Environment Information

windows
java 17

### Example Application

_No response_

### Version

5.3.3

Contributor guide

Open the contributing guide

Research direction

Start by reproducing layout resolution with a plugin containing views and main.gsp, a top-level Grails app, and several additional plugins, comparing jar and Tomcat behavior. Trace the plugin layout search entry point and establish a deterministic precedence or configuration, then verify that the view uses its intended layout rather than another plugin's layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
web-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.