Problem/Motivation
MessageCommand and the associated JavaScript API was added to Drupal core in 2019/Drupal 8.8.0, but was not used widely in Drupal core until 10.3.0, when the bigpipe module began using it to render messages created within bigpipe placeholders.
Because MessageCommand has not been used widely, many custom themes have not themed custom JavaScript messages.
For examples of how to override message theming, see:
core/themes/olivero/js/message.theme.js
and
core/themes/claro/js/messages.js
And the associated libraries-extend entries in those themes' .info.yml files.
Steps to reproduce
Original report:
Upgraded to 10.3 and status-message.html.twig is missing as a theme suggestion, breaking my custom theme. See screenshots.
Copied git bisect result from #24
2172d1009cec0e8f908a51fb2c99a1eb06b8b6da is the first bad commit
commit 2172d1009cec0e8f908a51fb2c99a1eb06b8b6da
Author: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu Feb 22 08:52:28 2024 +0000
Issue #3379885 by catch, Wim Leers: Use MessagesCommand in BigPipe to remove special casing of the messages placeholder
(cherry picked from commit 44c345dd9b8e2e1fb7131868a5d8b27c57e5b8e3)
core/modules/big_pipe/big_pipe.services.yml | 2 +-
core/modules/big_pipe/src/Render/BigPipe.php | 79 +++++-----------------
.../big_pipe/tests/src/Functional/BigPipeTest.php | 8 +--
.../FunctionalJavascript/BigPipeRegressionTest.php | 9 ++-
.../tests/src/Unit/Render/FiberPlaceholderTest.php | 4 +-
.../tests/src/Unit/Render/ManyPlaceholderTest.php | 4 +-
6 files changed, 32 insertions(+), 74 deletions(-)
Issue: #3379885: Use MessagesCommand in BigPipe to remove special casing of the messages placeholder
First bad commit: 2172d1009cec0e8f908a51fb2c99a1eb06b8b6da
Bad commit at the relevant file: core/modules/big_pipe/src/Render/BigPipe.php
Proposed resolution
See #149 adn #150, where catch and jonmcl agree the proper fix is in #3396318: AJAX MessageCommand markup and styling differs from Theme default and this can be closed as a duplicate.
There are several workarounds described in the comments.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3456176
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3456176-10.3-upgrade-now
compare
Comments
Comment #2
danthorneComment #3
cilefen commentedI looked through every change record for that release. https://www.drupal.org/node/3304793 stands out as possibly relevant. Could you investigate that?
Performing a
git bisecton a Git checkout of Drupal Core between the release tag you were on and the release tag that introduced the regression will very quickly find the regression commit.Comment #4
cozydrupalnerd commentedI noticed this too. I'm not sure how expanding the core theme suggestions for block view modes would remove the hook entirely for theme suggestions for the status_messages.
Comment #5
cilefen commentedIt may not be the cause. As I mentioned
git bisectwill identify the issue quickly.Comment #6
cilefen commented#3456525: status message notification twig file name changed
Comment #7
alexpottI've enabled twig debug in Drupal 10.3.x on the standard profile, install the system test module and used drush php to do
\Drupal::state()->set('system_test.front_page_output', 1);and visited the front page.... I seeIf I change core/themes/olivero/templates/misc/status-messages.html.twig then it affects the output.
So as I far as I can see this is working and has not changed.
Comment #8
danthorneI've just set olivero as the default theme on my site and modified /themes/olivero/templates/misc/status-messages.html.twig myself. It did nothing.
Comment #9
cozydrupalnerd commentedI tried what you suggested, and I am not getting any suggestions. I even went to manually update the Olivero twig template (just adding text of 'Hello World'), clearing caches, and still nothing.
This was done with a new minimal install, no custom modules.
Comment #10
prashant.cI tried with
Can't see the file
status-messages.html.twigin TWIG debug output.Tried to add some HTML etc. and clearing cache nothing worked.
Comment #11
danharper commentedGetting the same issue.
status-messages.html.twig is not being suggested.
I'm getting the same as #10
I'm using a subtheme which of a conrib theme. After updating to 10.3 the styling disappeared because the template is not being suggested.
Comment #12
f0ns commentedI am experiencing the same issue after updating to Drupal 10.3
status-messages.html.twig is not being suggested.
I'm using a custom theme that I made.
Comment #13
solideogloria commentedSame here. I'm using a custom theme that has Classy as the base theme.
Comment #14
sjhuskey commentedI'm having this issue with a subtheme of Radix.
Comment #15
prashant.cCould this https://www.drupal.org/project/drupal/issues/3270083 be related I tried to make the changes as per but still not getting applied, however, If I dump <?PHP $templates = drupal_find_theme_templates($existing, '.html.twig', $path); ?> when the status message is displayed it returns the template name in the array.
Comment #16
danharper commentedApplying the patch from that thread didn't solve the issue which appears to about sorting them.
I do have an error in my twig about invalid naming.
Comment #17
andikanio commentedMy current fix is like this, but this will only fix from using core into radix, it didn't go through my custom template.
Comment #18
danharper commentedMy Gin admin theme seems to work fine.
If I remove the status message block from the frontend theme then messages still display but in the content region (still un styled) is this normal behaviour?
Comment #19
alexpottIf I start from 10.3.x and do:
Here's the HTML I get for the status message that appears.
Comment #20
solideogloria commentedI set a breakpoint in
\Drupal\Core\Render\Renderer::doRender(). When theSystemMessagesBlockis being rendered,StatusMessages::renderMessages()is never called. Here is the block's$elementsarray:Note that it has
The theme is
[#theme] => block, so the theme suggestions are only suggestions for theming a block, not for theming status messages. Still, this shouldn't be causing the issue. The block has the samecontentin 10.2.Comment #21
solideogloria commentedIf I set a breakpoint in 10.2,
StatusMessages::renderMessages()is called. So the render placeholder element's callback is not being properly called in 10.3 somehow?Comment #22
cilefen commented@solideogloria Could you perform a git bisect on a Git checkout of Drupal Core to definitively identify the commit that changed behavior?
Comment #23
solideogloria commentedRE: https://www.drupal.org/project/drupal/issues/3456176#comment-15654990
@alexpott Could you please include more complete steps? I am not able to enable the system_test module...
Comment #24
solideogloria commented@cilefen Bisected. First time using that; it's really nice!
Issue: #3379885: Use MessagesCommand in BigPipe to remove special casing of the messages placeholder
First bad commit:
2172d1009cec0e8f908a51fb2c99a1eb06b8b6daBad commit at the relevant file:
core/modules/big_pipe/src/Render/BigPipe.phpComment #25
solideogloria commentedComment #26
solideogloria commentedComment #27
solideogloria commentedAdding the git bisection details to the issue summary.
Comment #28
solideogloria commentedComment #29
gorkagr commentedHi!
Experiencing the same error here with a theme based on Radix5.
This is the output I get on the theme:
Now, if i use the code of #17 in my theme:
, the output changes to:
and the message is rendered as it used to be
Comment #30
solideogloria commentedA workaround might also be to disable BigPipe, since the issue arises there.
Comment #31
gorkagr commentedIf in the class @solideogloria is mentioning (core/modules/big_pipe/src/Render/BigPipe.php), i comment (i know i should not, #17 works for me, i am not an expert of core but i have just tried):
(but as mentioned, try first #17 as a workaround as i have written in #29 it works for me)
the output is good and hey, it takes even less time (0.00482 segs vs 0.00868 segs):
Comment #32
umpire274 commentedI've the same issue with Bootstrap Barrio subtheme, but only with the status messages green. With alert messages I see the right output in red.
If I try to do the "solution" of #31 the issue is solved, but I know it is only a bad way.
Comment #33
ahmad khader commentedRemoving the following code makes it work normally I assume when it deletes the messages it stops using templates/misc/status-messages.html.twig' file
MessageCommand utilizes message.js for constructing the message (message_list) which restricts customization via template files when bigpipe is exploited for message rendering.
Possibly having a placeholder solely for the message string, instead of the rendering message, could make template customization possible.
Comment #34
gorkagr commentedAh, I forgot to mention that, it seems claro/gin themes are not affected (i believe big_pipe also works in admin mode but i am not sure about that)
claro/gin use different hooks and libraries for handle messages (hook_preprocess_status_messages and hook_element_info_alter), so that might be it fails on certain hooks??
Comment #35
catchPretty sure this is a pre-existing issue in Drupal core's AJAX messages command which has been exposed by the big pipe change. I've opened #3457518: The AJAX messages command should render messages using the twig template to fix it properly. Postponing this issue on that one. If there turns out to be something else going on here, we can unpostpone.
Comment #36
ahmad khader commented#34 Not really, Gin uses its own message.js to render AJAX messages; that's why it didn't change. However, if we debug the Twig file, we will see that it doesn't use templates/misc/status-messages.html.twig when BigPipe is enabled (AJAX message).
Comment #37
f0ns commentedUninstalling Big Pipe fixed the issue for me so this is a temporary workaround.
Comment #38
rajab natshahI confirm.
Works when I uninstalled the Big Pipe module.
Should this be fixed from Big Pipe, or in custom components?
Comment #39
catch@Rajab Natshah see #3457518: The AJAX messages command should render messages using the twig template which I opened just a couple of comments above.
Comment #40
rajab natshahNoted;
Thanks, catch, I had a look at it.
Exploring our options for a better general fix for this.
Our best option could be a general fix by fixing Big Pip or the message in system ( not to do this fix in 20, 100+ projects ).
Looking at the code of Trusted Callback in Olivero to check for
And
class OliveroPreRender implements TrustedCallbackInterface {Maybe it was fixed in Olivero in some way.
I noticed that many things needs a Trusted Callback in Drupal ~10.3.0 and Drupal ~11
Comment #41
rajab natshahMoving the conversation to #3457518: The AJAX messages command should render messages using the twig template
Comment #42
solideogloria commented... I'm not sure that's the whole of the issue. I override/redefine
Drupal.theme.messagein my custom theme so that the rendered HTML for Ajax matches my theme's template file. However, it's not getting called by these Ajax messages.If I copy BigPipe.php's changes to 10.2.7 so that the messages template isn't used and they are sent with Ajax, my custom
Drupal.theme.messageis called in Drupal 10.2.7 for other Ajax messages, but not for these Ajax messages sent by BigPipe. Same in 10.3.x.If you test with a controller (along with the rest of the controller, and a button or something that uses it):
And override
Drupal.theme.message:The override is called for the controller's Ajax response, but not for BigPipe's Ajax response.
As another note, only the last Ajax
MessageCommandis rendered. I think it recreates/replaces the messages wrapper, removing all prior messages.Comment #43
sjhuskey commentedI'm positing this here in case anyone just wants the status messages to be color-coded and minimally themed.
The quick fix (and one I can live with) is to copy the content of
web/core/themes/starter_kit/css/components/messages.cssinto your custom theme. I also had to uncheck the "Aggregate CSS files" and "Aggregate JavaScript files" atadmin/config/development/performance, save, clear caches, then recheck the boxes and save again before the changes took effect.Comment #44
laborouge commented+1 subscribe
Comment #45
cozydrupalnerd commentedFor those who are looking to do a temporary "fix" by bypassing the code in the updated BigPipe.php file (as mentioned in #17 and #31), I've created a patch that comments out that piece of code. Testing this, Big Pipe still works and the theme hook for status-messages comes back, and this should only be used as a temp. fix / workaround until it can be fixed correctly.
This patch will help you upgrade to 10.3.
Comment #46
laborouge commented#45 works for me on Drupal 10.3. Thanks.
Comment #47
chippyjacob commented#45 works for me. I have been checking this issue for the whole 1 day. Thanks
Comment #48
solideogloria commentedComment #49
danchadwick commented#45 worked as a workaround for my subtheme of radix v5. In my case, the messages receive no special CSS styling, making them almost unnoticeable. Saying the markup and theming "differs from theme default" is putting it mildly. Bumping to Major since it meets the criterion, "Interfere with normal site visitors' use of the site".
Comment #50
solideogloria commented#45 workaround works for me, too.
Comment #51
gorkagr commentedI have done a bit more testing in some of the sites i have:
Workaround on #17 works for the sub-themes made with bootstrap@3, radix@v4 & radix@v5.Radix@v6 works fine without #17 (actually, with #17 it causes duplicated messages)
With #17 in the sites i have tested it, workaround #45 has not been necessary, but i think also #45 is less theme-dependant and prompt to errors in some cases.My previous test is wrong, so i will do #45 and radix6, as it seems i have some issues there with #17
Comment #52
f0ns commentedThe patch in #45 did the trick and I could reinstall BigPipe. Thank you for the workaround!
Comment #53
d.fisher commentedThe patch in #45 also works for me.
Comment #54
catchI'm postponing this on #3457518: The AJAX messages command should render messages using the twig template again - that will resolve the issue that people are experiencing here. Fine to continue discussing workarounds here, but to actually fix it, we need to change how AJAX messages get rendered.
Comment #55
solideogloria commentedThe actual issue is #3396318: AJAX MessageCommand markup and styling differs from Theme default, since the other was closed as a duplicate.
Comment #56
ady1503 commented#45 NOT works for me on Drupal 10.3. Thanks.
I want to add:
1. I have uninstalled the BigPipe module and the notifications do not work either.
2. But the notifications of my personal code of the modules I create do not work. Yes, system notifications work, they all work.
3. A curious thing is that when I add to my code example "\drupal::messenger()->addStatus('Hello world');" of notifications a syntax error, the notification does appear and the error is also written to the log. I understand that it sounds strange but detect it.
4. All Drupal modules that customize notifications stopped working with drupal 10.3. I have reviewed everything and an issue is open in all of them.
Thank you I wait for the solution.
Comment #57
ady1503 commentedHello.
I inform you that works without any patch.
I am using olivero and gin drupal themes, core notifications works well. But:
For my custom code to work, type:
\Drupal::messenger()->addStatus(t('Dear %user, Welcome to our %site',['%user' => 'admin', '%site' => 'Drupal Learn']));
\Drupal::messenger()->addStatus(Markup::create('Duplicate Markup / string.'), TRUE);
exit(); <---
I have added only the exit() function, stop script.
I know it is not a correct solution, but in my functionality it works well for me.
I don't know why when adding exit(), after the notification functions works well.
Without exit(), custom notifications do not work. None, but with exit() at the end of the notifications function work.
I hope it is resolved correctly.
Gracias
Comment #58
solideogloria commented@ady1503 You must be doing something wrong in your modules. You definitely shouldn't be adding
exit()after those calls, as it will prevent any other code from running.Consider opening a separate issue, as your problem is likely something else.
Comment #59
ady1503 commented@solideogloria
Yes you're right.
But for me it works perfectly.
Because my notifications are to control access and number of content added. And stopping the script is not a problem.
I do redirect and then project the notification to inform the user that they do not have permission or have exceeded the number of allowed content.
I wanted to inform, if this is a reason for finding the drupal core problem, when it is solved I will return to the normal code.
Thank you.
Comment #60
psf_ commented#45 work for me too.
Comment #61
vipin.j commented#45 worked, Thanks.
Comment #62
catchComment #63
catchThe proper fix for sites experiencing this is:
1. If you have a custom theme, then implement
Drupal.theme.messagein your theme, there are examples of how to do this in both Claro and Olivero themes in core. Umami does not do this but #3100083: Add js message theme override to match Umami message markup is the issue to add that, and will show the kind of changes necessary.2. If you're using a contributed theme, open an issue against that theme's issue queue to add JavaScript messages support.
I've updated the issue summary with instructions. If we do #3396318: AJAX MessageCommand markup and styling differs from Theme default, that will mitigate this for themes that don't style JavaScript messages (because the messages would be rendered in PHP), but there could still be edge cases where sites see unthemed messages.
Comment #64
solideogloria commented@catch I already implement
Drupal.theme.message, and that doesn't fix the issue, because the function isn't being called for the BigPipe messages, but the function was called and worked for messages created with Ajax in other places of my site prior to 10.3. Only commenting out that BigPipe code with #45 fixes it.Comment #65
ady1503 commentedI make refactoring of mi code to
and mi notifications works without patch 45, with theme gin and olivero.
source: https://blog.birk-jensen.dk/drupal-http-redirection-from-anywhere
https://www.drupal.org/node/2023537
Comment #66
gorkagr commented@ady1503, as far as i tested, those themes are not affected by this issue, at least not to me. Olivero implements its own drupal.messages override (if i am not wrong)
Bootstrap, radix.. those yes (at least to me)
Comment #67
glynster commentedBest solution is to add to your theme preprocess andikanio #17
Comment #68
laborouge commented#17 works for me fine on Drupal 10.3.1.
Thanks.
Comment #69
2dareis2do commented+1 #17.
After half a day of investigation I ended up here as well.
hook_theme_suggestions_HOOK_alter and hook_preprocess_HOOK work as expected after this is called
Ok now I am also seeing message added twice after page reload. Message is appended with ajax message
e.g.
<div class="messages messages--status" role="status" data-drupal-message-id="status-812605616874536" data-drupal-message-type="status" aria-label="Status message">Antibot (views_exposed_form): disabled</div>This looks like it is added in ajax.js e.g.
If you clear cache, the message only appears once on page load, then it will appear twice.
Disabling Big Pipe stops the message being added twice. Actually disabling bigpipe seems to fix the problem.
Even with big pipe being disabled, message is displayed multiple times when pages loads via ajax (olivero).Actually this could be problem with the notification. Will investigate that first.Message/Notification seems to persist. i.e. is shown again even if the message/notification is manually closed.Comment #70
2dareis2do commentedComment #71
brandonlira commented#45 workaround works for me, too.
Comment #72
hyperlinkedCreating a custom preprocess hook for system_messages_block as shown in #17 worked for me, but I ran into caching problems with the messages block. The message output would get cached and it would display the cached message every time.
I had to set the cache max-age to 0 for this to actually be usable. Did anyone else encounter this too?
I ended up needing to do this:
Comment #73
brandonlira commentedThe best solution for me was to use solution #17, adding a preprocess in my custom theme and adding the following code along with that solution:
$variables['#cache']['max-age'] = 0;Comment #74
hyperlinkedOK, so I wasn't the only one. That's exactly what I did as well. I guess the workaround in #17 wasn't complete. If anyone is having issues with messages getting cached and frozen, you'll need to use the code in #72 until there's a proper fix for this.
FWIW, the patch in #45 worked in the sense that my system messages came back, but I also had the issue with the cached messages using that as well so I rolled back that patch and am only going with the preprocess function as the workaround.
Comment #75
ryan-l-robinson commented+1 for the workaround in #72.
On my dev site that had these in the settings:
Everything seemed fine with just #17. When it went through to the staging site, I saw the "All caches cleared" message on every page. So I added the line in #72 which seems to work so far on local even when I commented out those lines in the settings file, but I'll update this if it turns out to not fix it on the real staging.
Comment #76
hyperlinkedRyan, setting your cache bins to null in your settings disables page caching, which is basically like setting cache.max-age = 0 to everything on the site. That's handy for the dev site, but you won't want that on your production site. If that was what you had resorted to, you don't want to do that as your workaround.
Comment #77
glynster commentedYup great job on the caching tweak. I feel like this could be added to the sub theme as a tiny default tweak?
Comment #78
ryan-l-robinson commented@hyperlinked
Sorry, poor wording on my part. I meant that I had those cache bins as null on local/dev, not on staging or production.
Your explanation makes sense for why I was seeing the constant alert on staging (still has the default cache bin) but not on local/dev (null cache bin site-wide).
I have now followed the lead of #72, which if I'm understanding correctly means no caching of alert messages, but maintains the caching everywhere else.
Comment #79
bernardm28 commentedHere is how we did it and how it can be done with the new way described by catch #63.
https://www.drupal.org/project/uswds_base/issues/3465493
My example is for a USWDS theme but you can replace those classes with those you had on status-messages.html.twig
Comment #80
catch@bernardm28's approach is the correct one here.
This isn't actually a new way to theme status messages, it's been in core since 2019 and Drupal 8.8 https://www.drupal.org/node/3086403. Any status message created via AJAX has used this mechanism since then. The difference in Drupal 10.3 is that BigPipe also started to use the same mechanism, which means it's used a lot more often.
@solideogloria if you definitely have this working for other AJAX status messages but not in big pipe, please open a new issue about that - it ought to be impossible for it to be different, because it's all executed via the same JavaScript API.
Comment #81
hyperlinked@catch would there be any harm in the forseeable future with fixing this via the workaround in #72 for a non-contrib legacy theme?
Comment #82
solideogloria commented@catch It appears that messages that I was already adding via Ajax are rendered/themed properly without patching BigPipe. But the messages that are added using
$this->messenger()->addMessage()(e.g. in a Block'sbuild()function) are not.When I use this block with patching BigPipe, I can see an Info message (a new type of message supported by the Webform module), as well as other standard messages that fit my theme. When I remove the patch, I get an error
(I tried to override
getMessageTypeLabels, but couldn't. My overriding function is never called.)And if I comment out that message line, the messages display but not with my overriden theme function
Drupal.theme.messagebeing called in my custom theme, so it doesn't fit my theme's style.Edit: I noticed that the Drupal variable is being converted when my TypeScript is compiled. I'll need to look into this and see if that's a cause.
Edit 2: Nope. TypeScript's build process shouldn't affect this at all.
Comment #83
catch@solideogloria can you try this without the info message from webform? This sounds like the webform info message is incompatible with Ajax rendering which would be a webform issue.
Comment #84
reece.oliver commentedWhen having the messages styled through
status-message.html.twigit grouped messages of the same type into a list. Is it still possible to do this via message.js as from reading the code it callsDrupal.theme('message', { text: message }, options),for each message then appends it to the element messages__wrapper. I would like to keep the old format to save my screen from being cluttered with multiple alert elements if there are multiple messages to be displayed.Comment #85
acbramley commentedThe postponed issue is in, what are the next steps here? I can't see a proposed solution in the IS and the MR is empty.
Comment #87
catch@acbramley the only way to make status messages the same for ajax vs. non-ajax responses for all themes would be to do #3396318: AJAX MessageCommand markup and styling differs from Theme default, that would mean rendering the messages in PHP, then adding that HTML via AJAX, instead of adding the message string/type in MessagesCommand and then doing the rendering in js. The mis-match happens when themes don't implement js theming of messages.
I postponed this issue on that one in #35 but that apparently didn't help to focus efforts over there.
Comment #88
acbramley commented@catch that's a shame, I think this is going to bite quite a few people on 10.3 and the new way of implementing it in JS is not obvious at all.
Perhaps we could at least warn people if they've got an overridden status messages twig template that it's not going to do anything and direct them to documentation on how to do it properly
Comment #89
catch@acbramley it's not actually new, it was added in Drupal 8.8, but agree it's not obvious at all.
Another option would be to revert the big pipe change from 10.3 and 11.0 and try to get the other issue into the next minor.
Comment #90
acbramley commented@catch Ah yeah sorry, new as in having a customised
status-messages.html.twigtwig template in your theme does not work anymoreComment #91
acbramley commentedI've also just found some very strange behaviour where the new JS themed messages are not being used for anonymous users. Both for webform submissions and even password reset submissions they're unthemed.
We're using the same method as Olivero so I'm not sure what's going on here.
When logged in everything works fine.
Comment #92
astoker88 commentedHas anyone succeeded in applying the modified #17 patch whilst keeping bigpipe enabled?
Seems on my install at least that the steps are
1.) Disable bigpipe
2.) Add the preprocess hook
Comment #93
umitThese update problems of Drupal are so annoying that I'm at the point where I'm going to quit. There is no documentation on the subject. Why would they make such a change without consulting the community. I am not updating any site because of this issue.
Comment #94
glynster commentedWe use this in a custom theme without disabling bigpipe
Resolved issues for us.
Comment #95
pandaski commented@glynster thanks for this information
Comment #96
sevenfish commented@glynster Thanks. Working now
Comment #97
2dareis2do commentedBefore applying patch my mark up is like this with big pipe enabled (looking good but status message is output multiple times, one on top of the other):
After patch message is output
oncemultiple time and markup is like so (not looking good - see attached). This also shows output being output multiple times!In this example antibot notice is output to status message.
If I disable Bigpipe and remove the patch output is like so. Status message is
notstill repeated but output still looks good, but the curious thing is when I copy from the browser markup does still appear to be appliedtwicemultiple times!10.2 with Bigpipe disabled (and show form id on antibot settings):
10.2.7 with big pipe enabled:
Comment #98
2dareis2do commentedScreenshot with big pipe disabled.
Comment #99
2dareis2do commentedattached picture shows 10.2.7 with and without big pipe enabled works without outputting markup multiple times and is also styled.
Comment #100
2dareis2do commentedApologies for all the noise but to clarify I think I am conflating a few issues here.
@glynster solution does resolve the theme hook suggestion issue for me after upgrading to 10.3 with Bigpipe enabled.
The other things i noticed when looking into this issue is that the initial notification (on page load is shown in the Status messages block. For me this is out put in my notification region. Subsequent ajax loaded notifications do not appear in the same region. For me they are getting injected in the view (views-view.html.twig) or content area for example. This could be an issue here or with views load more that I am using here. Not sure. Same in 10.2.x My expectation is notifications should be output in the same block or region as specified in your site.
I have added (another) screenshot that shows the output being added twice to message on initial page load notification. After that it only seems to get loaded once. Setting cache max age to 0 using THEME_preprocess_HOOK seems to address that issue.
Comment #101
acbramley commentedRe #97 - any chance you could remove that HTML and add it as an attachment instead to reduce the noise? It's quite hard to parse as is anyway
Comment #102
2dareis2do commentedThanks @acbramley
It is useful to see the output side by side but I will consider uploading markup as attachments in the future as per your recommendation.
The problem I see with this approach (patch) is that there is also an issue with core Oliveiro theme afaict. Please see attached screenshots.
In Oliveiro Initial status message is shown in correct place on page load in this case is also has the following markup:
Notice that both
aria-labelledbyanddata-drupal-message-idhave the following token attached590833649505219The markup for the second message that is injected does not have this token markup also looks a little different:
<div class="messages-list__item messages messages--status" data-drupal-selector="messages" role="contentinfo" aria-label="Status message" data-once="messages">We can see also role is
contentinforather thatstatusso I a little confused about that.In Olivero the message notification keeps on injecting and error is found in the console log. See attached.
So to summarise in Oliveiro:
ResizeObserver loop completed with undelivered notifications.Tested in Safari, Chrome and Firefox.
Perhaps I should open up another issue(s) for some of these?
Comment #103
2dareis2do commentedProblem with Olivero seems to happen even with Bigpipe disabled.
Tested in Stark and seems to work fine with and without Bigpipe enabled. Message notifications are un-styled in Stark though.
Perhaps the issue in Olivero is a different one as I think the implementation around message notifications is different there. e.g. it has its own messages.js and message-theme.js which also seem to have dependency on navigation-utils.js
Comment #104
2dareis2do commentedI have raised issue for Olivero here:
https://www.drupal.org/project/drupal/issues/3469942#comment-15741587
It's a shame that there appears is no easy way in core to see how message notifications should be implemented.
Comment #105
2dareis2do commentedTurns out even Olivero does seem to need this fix/patch for theme suggestions. Please see related issue for more info.
There is quite a lot happening here with how notifications are styled depending on:
1. the role or status of the alert/message (status, error, warning, info?)
2. if BigPipe is enabled (alerts are grouped together only if Bigpipe enabled?!)
3. If there are single or multiple alerts (depends is container is tagged with
contentinfoorstatusrole4. if views is enabled, they can be output to multiple regions?! (notification sits in main notification region and block on page load while additional notifications are output in the content region)
I actually came across alerts a while ago when looking at theming migrate tools UI and the limitation of the current traffic light system (red, green, amber). If any one is interested there is also figma design there as well.
https://www.drupal.org/project/drupal/issues/3437924
The good news is i seem to be able to apply https://www.drupal.org/project/drupal/issues/3456176#comment-15738200 in versions of Drupal prior to 10.3 without any noticeable side affects. This means I can avoid having to do a major release for any theme to address issue or changes introduced with 10.3 release.
Certainly upgrading to 10.3 without applying these changes can lead to un-styled alerts and message notifications.
Comment #106
mingsong@acbramley, If you turn on the Twig debug information, can you see what template is used for the status message?
According to my test with Drupal 11, the message showing to authenticated user is rendered from the core/modules/system/templates/block--system-messages-block.html.twig template.
Meanwhile, the message showing to anonymous users is rendered from the core/themes/olivero/templates/misc/status-messages.html.twig template, which is the front theme on my test site. In your case, it might be from your custom theme.
I think that’s why the results differ between anonymous and authenticated users.
By the way, with Drupal 10.2, the them's status-messages.html.twig template is consistently used regardless the authentication situation.
Comment #107
catchThere's now an MR to consolidate the theming of status messages over on #3396318: AJAX MessageCommand markup and styling differs from Theme default which looks like it still needs some work on test fixes but could use early reviews/testing.
If we're able to do the approach there, the markup between messages that are sent from PHP, AJAX and pure-JavaScript messages should be identical, since it will use the theme's twig template to generate the markup for the JS messages too.
I'm postponing this issue on that one, since if we commit it over there, it should fix everything here. Except for the inconsistency noted in #3456176-106: 10.3 upgrade now missing status-message theme suggestions but that's another issue again.
Comment #108
mingsongSorry for commenting on a postponed issue.
I think the reason why the message rendered looks different between anonymous user and authenticated user is that in a page rendered for an authenticated user, there is another big-pipe placeholder callback for the toolbar was called prior to the call of Drupal\Core\Render\Element\StatusMessages::renderMessages(). That causes all messages were deleted in line 529 before the messages were rendered.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/big_p...
Since the anonymous user won't have toolbar, the big-pipe placeholder for the message is the only one in that page, so that the renderMessages() is called before the messages were deleted in line 529.
Comment #109
drubbThis bug is really hard to understand for site builders.
For me, the workaround in #45 works, but this should
definitely be fixed in core!
Comment #110
ryrye commentedFor me #17 was the cleanest solution until this is resolved, no patch to core.
Comment #111
gaëlgFor anyone facing the same: I had a problem with Devel module when dumping objects or arrays through dpm(). Everything normally collapsed (sub-arrays,...) was expanded and not collapsible.
I could get rid of the problem by disabling Big Pipe (and Big Pipe Sessionless). Or by applying patch #45.
https://gitlab.com/drupalspoons/devel/-/issues/543
Comment #112
apparatchik commentedThank you at #111 for testing this, I can confirm patch #45 works for the time being, dpm and kint are essential to our dev process.
Comment #113
tomefa commentedCan confirm too, i use patch #45 and it use my status-message template.
Comment #114
guistoll commentedPatch from #45 works for me as well.
Comment #115
eddylbsPatch from #45 works for me too.
Thank you.
Comment #116
ryanfc78 commentedPost #94 fixed it for me in my theme without messing with BigPipe.
Comment #117
f0ns commentedI got rid of the patch and added the preprocess block as suggested in comment #92 and #94.
This works with bigpipe.
Thank you, this is the cleanest solution for now (for me) as I don't have to patch core.
Comment #118
luke adams commentedJust wound up here as well after updating to 10.3. Seems like BigPipe is the issue.
Note: If you're hosted on Pantheon, you can simply disable BigPipe module to resolve the issue, no patching or custom code required.
Ref: https://docs.pantheon.io/modules-known-issues#bigpipe
Comment #119
dragos-dumi commentedAdding #94 does solve the issue in a way, but it seems it introduces another issue. on a page that's cached in dynamic page cache, if there's a message to be displayed, it will append at the bottom because it does not find data-drupal-messages-fallback . the fallback markup seems that is not added when rendered this way !?
Comment #120
umitThis problem should be solved in drupal core, the status message does not work properly on custom themed sites.
Comment #121
sokru commentedFor us the MR on related issue #3396318: AJAX MessageCommand markup and styling differs from Theme default does not fix the issue. We have a custom module with form_alter that places custom inline status message on specific place. After the #3379885: Use MessagesCommand in BigPipe to remove special casing of the messages placeholder all status messages are rendered on same place:
This issue can be reproduced easily with core (11x.) by creating a custom module with following code and setting the site to maintenance mode and going to "/node/add/article".
Comment #122
oscarclement commented#17 works for drupal/core (10.3.8). I just tried it
Comment #123
_renify_ commentedComment #124
jonmcl commentedEdit: Striking my comment as not being particularly constructive.
Comment #125
ian.ssu commentedWe encountered this system message styling issue while upgrading from 10.2.12 to 10.3.11. Our theme is based on Radix 5.
Disabling BigPipe (#30) was a workaround, but
yourtheme_preprocess_block__system_messages_block(#17) didn’t work.Since Radix 6 already fixes this, I backported the solution instead of upgrading.
{theme}.info.yml:(example: radix_starterkit.info.yml)
{theme}.libraries.yml:(example: radix_starterkit.libraries.yml)
{path}/{to}/message.js(example: message.js)
Comment #126
bryanmanalo commentedFor me, using this patch, together with (legacy) bootstrap_barrio:5.1.12 subtheme:
https://www.drupal.org/files/issues/2024-12-04/3456176-bootstrap_barrio-...
Created an issue where:
(1) Clear all caches persists on multiple pages
(2) For anonymous users, applicable status messages (for examples, views_data_export), the messages are unthemed in the footer.
The solution in the end for me was to implement my own message.js in my subtheme, guided by comment #125 and the issue description.
Comment #127
uv516 commentedDrupal 10.4.3:
The patch in #45 helped me.
Comment #128
uv516 commentedYous updated to Drupal 10.4.4 and the problem is back again :(
#45 helped me again, but could i be fixed permanently? - I have to edit several sites to fix it.
Comment #129
catchThe permanent fix is likely to happen in #3396318: AJAX MessageCommand markup and styling differs from Theme default. Testing and reviews on that issue would be very welcome (although it needs a fresh MR on there at the moment).
Comment #130
ericdsd commentedAdapted patch from #45 to core 10.4.6 to workarround barrio related issued reported in #126 when also applying patch from #123.
Comment #131
tregonia commentedFinding that the changes described in #94 work for messages like clearing caches and editing content success, but it does not work when used with Views batch processing. In fact, the messages placeholder is removed, and the system message block outputs nothing but BEGIN/END OUTPUT.
The view in question is a views_data_export (8.x-1.5) on Drupal 11.1.6. When batching is included on an export with over 3500 rows, the file generates, but the message to download the file never pops up. Removing the preprocessing function allows the messge to be display, albeit unstyled.
Comment #132
nikita_tt#45 variation for 11.1.6
Comment #133
rp7 commentedI can confirm #131.
The preprocess-hook workaround being mentioned here doesn't cut it for showing batch results.
Comment #134
carlitus commentedFor me, with the patch from https://www.drupal.org/project/drupal/issues/3396318, now it's working.I looked at it wrong, it doesn't work
Comment #135
quietone commentedJust adding what this is postponed on to the remaining tasks per Remining tasks. I had to restore the standard issue template to do that. In the future, keep all the issue template heading as they are used to track progress and various tasks on an issue.
Comment #136
lbesenyei commented#45 works for us on Drupal 10.4.
Comment #137
fathershawnI posted the following at #32 in #3396318: AJAX MessageCommand markup and styling differs from Theme default
If that proposal is agreeable, this issue would be used to add the theme hook core and template to core themes.
Comment #138
danchadwick commentedReroll of #45 for drupal 11.2
Comment #139
lindsay.wils commentedThank you @danchadwick, this was holding me back from running the latest updates, very much appreciated!
Comment #140
d.fisher commentedCan confirm #138 applies cleanly to Drupal 11.2.
Comment #141
simobm commented#125 Worked perfectly for me, i'm on D 10.5 using Bootstrap barrio,
When using MessageCommand i would end up with html that could not be modified to adapt my styling.
Comment #142
uv516 commentedI just upgraded to Drupal 11.2 and it seems the problem is gone.
Comment #143
d.fisher commented@uv516 is that with the patch or without?
Comment #144
uv516 commented@d.fisher: It was without the patch.
Comment #145
d.fisher commentedInteresting. I will test without the patch.
Comment #146
uv516 commentedI newer used patch #125. Only #45 in Drupal 10 (10.3 to 10.5).
Comment #147
d.fisher commentedI can confirm I am also seeing this issue fixed in Drupal 11.2.2. What do we do now? Close as fixed?
Comment #148
jonmcl commentedCan anyone locate the commit(s) that fixed this issue in 11.2? Then I'm hoping we can create a back port to 10.4.x.
Comment #149
catchThis isn't actually fixed in 11.2 as such in the same way it wasn't broken as such in 10.3. It happens less often in 11.2, after 10.3 made it happen more often.
If you have a theme that doesn't implement JavaScript message theming, then that is a bug in the theme that can only be fixed in the theme itself. Various subsystems may or may not result in more or less JavaScript messages being added on a site.
10.3 changed the way that big pipe renders status messages so that they're rendered via the AJAX system - this results in more js messages on a site, so it is more obvious when the theme doesn't support them - hence the dozens of people finding that out in this issue.
The workarounds in patches here undo the 10.3 logic but do not resolve the underlying issue.
#3396318: AJAX MessageCommand markup and styling differs from Theme default changes things so that js messaging no longer requires explicit theming at all - the theming would be done by Drupal, the AJAX or pure-js messages would use that theme template for js rendering. Anyone who would like to see this overall problem fixed in a sustainable way in Drupal core should please test/review that issue.
Drupal 11.2 changed how BigPipe messages are rendered again, so that messages that are set on a previous request are no longer rendered via big pipe - this happened in #3508299: Support a placeholder strategy denylist for #lazy_builders.
However, if a message is set while generating a placeholder (e.g. during the rendering of the current page by big pipe), that will still be rendered by the AJAX system and it comes back to whether the theme implements js message theming or not. Those remaining messages (rarer but not impossible) are the ones, along with a few other cases, that #3396318: AJAX MessageCommand markup and styling differs from Theme default would sustainably fix.
Having said all that, if the frequency of this is reduced in 11.2 to the same level it was happening in 10.3, then there is no need for this issue to be open to document workarounds, and we could properly close it as a duplicate of #3396318: AJAX MessageCommand markup and styling differs from Theme default.
Comment #150
jonmcl commentedThank you for the detailed explanation @catch! I think the work being done under #3396318: AJAX MessageCommand markup and styling differs from Theme default is the right permanent solution.
I am intrigued by some of the functionality being shown in #3508299: Support a placeholder strategy denylist for #lazy_builders and I need to dig deeper into the
#placeholder_strategy_denylistattribute.For now, we will be relying on the core patch provided in this issue to keep the problem from surfacing on our 10.4.8 app using the uswds_base theme as our base.
Thanks again!
Comment #151
quietone commentedCame here because the version in 10.3.x, which is no longer supported.
That last two comment think this is a duplicate, where the correct fix is in #3396318: AJAX MessageCommand markup and styling differs from Theme default. So I am going to close this as a duplicate and update credit. If you think the credit is wrong, ping me in @contribute on Slack.
I've updated the Issue summary to mention the correct fix and that this issue documents workarounds.
Thanks