Problem/Motivation
Duplicate AJAX wrappers are causing some errors to be rendered twice.
Symptoms have been reported around file field and image field.
In #115 @lauriii notes the element prefix and suffix are added in the twig template, as well as in the renderer.
Steps to replicate using the File field:
- Add a file field to basic page content type. Make sure the cardinality is set to greater than 1.
- Upload file of any type other than text.
- Double error is triggered.
Proposed resolution
Fix this by not rendering prefix and suffix twice if #render_children
is set.
@xjm notes the #render_children
property is defined in core/lib/Drupal/Core/Render/Element/RenderElement.php
Remaining tasks
Example of a user interface change
Show error once, instead of twice! :-) This is just one example. There are likely other places that will be impacted by this change.
Before patch:
Patched:
API changes
None
Data model changes
None.
Discussion Summary
@idimopoulas reports doing a manual review at #177
@Fabianx explains the problem clearly in #134 and provides a patch at #137
@joelpittet manual review with screenshots at #122
@swentel reports symptom is fixed for image fields but still occurring for file fields in #69
Original report
If I edit my profile, and upload a picture to Picture field, after that I see the messages but twice all times. (drupal_render() should check if it's rendering a 'render element' and if so call drupal_render_children() (inline) instead (1920886) ) not about the ajax its just rendering the element.
I find these message only one place (/core/modules/file/file.module;466) and I think somewhere is called twice. István Palócz see that bug, and he said the problem somewhere in ajax response.
Comment | File | Size | Author |
---|---|---|---|
#258 | interdiff-2346893-232-233.txt | 1.41 KB | Tanvish Jha |
#233 | 2346893-233.patch | 10.46 KB | alexpott |
#233 | 232-233-interdiff.txt | 1.41 KB | alexpott |
#232 | 2346893-232.patch | 9.79 KB | alexpott |
#228 | drupal-duplicate-ajax-wrapper-2346893-227-D8.4.patch | 956 bytes | ivan.chavarro |
Comments
Comment #1
Rade CreditAttribution: Rade commentedI was able to reproduce the issue and investigated a bit further. It seems the issue is with the ajax upload showing messages twice, not with the user system. The file is not uploaded twice, it's just the messages being shown twice.
In the attached screenshot you can see that the same issue occurs when adding an image to an article. I added a maximum resolution to the image field settings so that uploading would produce a message.
Comment #2
Rade CreditAttribution: Rade commentedI believe the problem is related to the fact that within the image field DOM, there are two identical ajax wrappers, and the status messages will appear directly after those.
Not sure how to fix this. Maybe the component should be "file system" instead of "ajax system"?
Comment #3
pp CreditAttribution: pp commentedClarify the title
Comment #4
Rade CreditAttribution: Rade commentedI'm working on this today in the sprint in amsterdam.
Comment #5
Rade CreditAttribution: Rade commentedThis issue might be related in some way #2187757: Add form id as form's inner div id attribute to use as ajax wraper
Comment #6
Rade CreditAttribution: Rade commentedI'll leave this for now and maybe pick it up some other time. Anyone feel free to continue on this!
Changing component to forms system as I believe the issue is related to it, more than the ajax system.
Anyone investigating this, have a look at these lines in ManagedFile.php
That's where the wrapping div comes from.
Comment #7
klakegg CreditAttribution: klakegg commentedThis may be found in FileWidget.php:
Comment #8
benelori CreditAttribution: benelori commentedConfirming this bug...the form item(the container) and the inputs(file widget itself) are wrapped in a div with the same id, which makes the replaceWith method display two error messages.
Comment #9
Rade CreditAttribution: Rade commentedI'll have a look at this.
Comment #10
Rade CreditAttribution: Rade commentedI can confirm that the bug exists for both image and file fields, as seen in the screenshot below:
Comment #11
Rade CreditAttribution: Rade commentedThis patch fixes the bug for image fields, but not for file fields. Need to investigate further.
Comment #12
Rade CreditAttribution: Rade commentedWhen commenting out these two lines, both Ajax wrappers disappear from file fields. So somewhere the prefix and suffix get duplicated...
Comment #13
Rade CreditAttribution: Rade commentedStarting to believe this might be file system bug, so changing the component.
Comment #14
Rade CreditAttribution: Rade commentedAlso, I'm not working on this anymore now so anyone feel free to contribute.
Comment #15
lauriiiSending to bot
Comment #17
lauriiiI found the reason for this. I don't know why we're processing the parent also while building file widget. First gonna check what testbot says and then I might investigate more.
Before:
After:
Comment #19
lauriiiOk more about the problems we're having now #2172241: Files and image widgets completely broken
Comment #20
Rade CreditAttribution: Rade commented@lauriii: Patch in #17 fixes the issue only image widgets, not for file widgets. That's pretty much the same I tried in #11.
Comment #21
Vj CreditAttribution: Vj commentedCan you please try following patch
https://www.drupal.org/node/2349835#comment-9453065
Comment #22
lauriiiThis is the latest patch from the duplicate issue. It clearly fixes the problem at least in all cases I tested.
Comment #23
Vj CreditAttribution: Vj commentedI have tested patch https://www.drupal.org/node/2349835#comment-9453065 with following cases :
1. File / Image field from content types
2. User profiles image
3. Ckeditor Image widget
Comment #26
jeqqI've tested https://www.drupal.org/node/2346893#comment-9466125. It works fine for all cases I tested.
Comment #27
alexpottThis seems a pretty fundamental change to the rendering system - we need needs to for this.
If this fix is correct then we should do it like this:
Also we should add a comment about why this is necessary.
Comment #28
RavindraSingh CreditAttribution: RavindraSingh commentedComment #29
RavindraSingh CreditAttribution: RavindraSingh commentedThanks laurii making it for more simpler. I just added the code in as @alexpott said, its fine if we are initializing if markup doesn't exists and adding markup if prefix and suffix exist.
Comment #30
RavindraSingh CreditAttribution: RavindraSingh commentedComment #31
oriol_e9g1. s/esixts?
2. remove extra final whitespaces
Comment #32
oriol_e9gOps!
Comment #33
RavindraSingh CreditAttribution: RavindraSingh commented@oriol_e9g, only one line was adding white space has been removed now. updated patch is attached here. Thanks for reviewing.
Comment #34
RavindraSingh CreditAttribution: RavindraSingh commentedComment #36
RavindraSingh CreditAttribution: RavindraSingh commentedRemoved more white spaces with fix.
Comment #37
RavindraSingh CreditAttribution: RavindraSingh commentedComment #38
oriol_e9gesixts should be exists
Comment #39
RavindraSingh CreditAttribution: RavindraSingh commentedFixed the typos
Comment #40
Vj CreditAttribution: Vj commentedremoved extra lines.
Comment #41
ifrikApplied the patch in #40 and it fixes the problem reported in #2409181: Error message displayed twice.
Comment #42
csardev CreditAttribution: csardev commentedThe patch of comment # 40 solves the problem and also resolve the issue https://www.drupal.org/node/2409181
Comment #43
vacho CreditAttribution: vacho commentedI applied the patch in #40. It is works.
Comment #44
harshil.maradiya CreditAttribution: harshil.maradiya commentedit working fine
Comment #45
alexpottStill needs tests.
Comment #46
idebr CreditAttribution: idebr commentedI traced this back to #2172241: Files and image widgets completely broken. By calling the parent::process() function the field is processed multiple times resulting in duplicate markup, so I copied the necessary code from the parent function to the ImageWidget.
Comment #49
Fabianx CreditAttribution: Fabianx commentedYes, the fix for the double process seems correct (though I have not checked the patch in detail, yet).
But this might be also related to #1920886: drupal_render() should check if it's rendering a 'render element' and if so call drupal_render_children() (inline) instead, which was fixed, but IMHO not totally fixed properly.
I just bring this to attention again - as the original patch changed the #render_children logic ...
Comment #51
gauravjeet CreditAttribution: gauravjeet at Material commentedI tested the patch and got the issue resolved. Patch in #46 seems to have done the fix.
Not changed status to RTBC, looks like @Fabianx #49 has to relate this issue to something else ?
Comment #52
RavindraSingh CreditAttribution: RavindraSingh as a volunteer and at Material commented@Fabianx, I didn't find this issue relates with the added issues by you.
Patch in #46 seems to have done the fix as @gauravjit also mentioned.
Moving this to RTBC for committer to get more feedback if issue come back.
Comment #54
idebr CreditAttribution: idebr at One Shoe commentedI doubt this is related. I'll poke the testbot again to make sure.
Comment #57
mondrakeComment #58
idebr CreditAttribution: idebr at One Shoe commentedComment #60
mondrakeNote - 'file.ajax_upload' route is being removed as part of #2500527: Rewrite \Drupal\file\Controller\FileWidgetAjaxController::upload() to not rely on form cache which is a critical.
Comment #61
idebr CreditAttribution: idebr at One Shoe commentedIt appears I botched the test only patch. Attached is a correct one. The contents is unchanged.
Comment #67
Rade CreditAttribution: Rade commentedApplied #61 and it seems to fix the issue with image fields only. The issue still exists with file fields.
Comment #68
Mile23I can't repro the problem. Is this maybe already fixed elsewhere?
Comment #69
slashrsm CreditAttribution: slashrsm at Examiner.com commentedThis is fixed for image fields but remains problem with file fields.
Tagging with UX since printing double messages isn't the nicest experience.
Image field seems to be fixing this by adding this code in the template_preprocess_image_widget() and printing "data" instead of "element" in the template:
File widget uses entire "element" instead which causes #suffix to be printed twice.
Comment #70
slashrsm CreditAttribution: slashrsm at Examiner.com commentedApplied #61 and it doesn't fix the issues (obviously since it touched Image widget only).
Comment #71
Mile23It seems like the test from #61 could be modified for any of the fields where this is still a problem.
Comment #72
slashrsm CreditAttribution: slashrsm at Examiner.com commentedThis fixes the problem for file fields too. I kept the test from #61 (it makes sense to test image fields too) and added similar test for file fields.
Fix is not the nicest. I'd prefer similar solution to the one image field has. That would mean BC-breaking
file_managed_file
template, which is not acceptable at this point.Comment #75
slashrsm CreditAttribution: slashrsm at Examiner.com commentedComment #77
marcingy CreditAttribution: marcingy at Examiner.com commentedLooks good
Comment #82
slashrsm CreditAttribution: slashrsm at Examiner.com commentedComment #87
slashrsm CreditAttribution: slashrsm as a volunteer commentedSeems to be passing.
Comment #91
alexpottWe need a comment here to explain why.
It also seems to me that this fix would be worth getting in during RC. But for that we need to add a statement to the issue summary of why we need to make this change during RC, including what happens if we do not make the change and what any disruptions from it are. We can add a section
<h3>Why this should be an RC target</h3>
to the summary.Comment #92
gauravjeet CreditAttribution: gauravjeet as a volunteer and at Material commentedAdded comment as suggested by @alexpott
Comment #93
gauravjeet CreditAttribution: gauravjeet as a volunteer and at Material commentedChanged status -> Needs review
Comment #98
slashrsm CreditAttribution: slashrsm at Examiner.com commentedRephrased comment a bit and attempt to fix corrupt patch. Added RC triage part to the summary.
I propose that we open a 9.0.x issue to fix this as part of the template as described in #72.
Comment #99
marcingy CreditAttribution: marcingy at Examiner.com commentedRtbc'ing assuming it is green
Comment #104
alexpottBut you're not removing double errors - you're remove the prefix and suffix because it already exists elsewhere. TBH this seems a strange place to do this - I think we should be doing this where the duplication occurs - but I guess that is what you are hinting at with saying that this would take a template change.
Comment #105
swentel CreditAttribution: swentel commentedpfew, this is a silly bug. Patch didn't apply anymore, so a reroll first. Not sure if there's a better place either to fix this bug.
Comment #106
swentel CreditAttribution: swentel commentedSo looked why the image field didn't have this problem and the reason is that it's using a dedicated theming function for the widget and a template file. Still have no clue where the double wrapper comes from though, but without that template file the image widget would suffer from the same problem.
We could do this for the file widget as well, problem is that the managed file element would still have the problem then, and probably individually using the image element has the same problem. Digging further.
Comment #107
swentel CreditAttribution: swentel commentedStarting to wonder if this a general problem anyway, just stumbled upon #2630960: Doubled pre- and suffix in datetime FormElement, will do some tests with prefixes and suffixes.
Comment #108
swentel CreditAttribution: swentel commentedSo this is a different approach, which @lauriii already proposed in #22 and effectively works.
I couldn't come up with a decent comment yet, because I'm not entirely sure what happens there in the render process (that function is quite complex - which is an understatement)
Comment #109
Wim LeersWelcome to drupal_render()! This particular part of it is equivalent with the D7 logic.
Comment #110
swentel CreditAttribution: swentel commentedNote, then in the end I'm running with #105 - so maybe we should go with that one and be done with it.
Comment #111
deepakrmklm CreditAttribution: deepakrmklm at Zyxware Technologies commentedThis patch works fine for me in 8.02.
Comment #113
juanramonperez CreditAttribution: juanramonperez commented#105 works for me.
Comment #114
catch#105 at least needs a better comment to address @alexpott's comment in #104.
Comment #115
lauriiiI just spent a nice day debugging why is this necessary and why is this the right thing to do. So what happens there is that the render element is being rendered in the
file-widget-multiple.html.twig
template which is used in a children of that render array and the prefix and suffix will be added as a result in there. Also when the render element itself is being rendered in the Renderer the prefix and suffix is added. Prefix and suffix should be only when actually rendering the render element.Comment #116
lauriiiAssigning for Cottser's review since I believe he has most idea what's happening there
Comment #118
lauriiiComment #119
lauriiiRemoved some of the unnecessary documentation
Comment #120
lauriiiComment #121
lauriiiPair coded the next iteration with @joelpittet
Comment #122
joelpittetReviewed the code for the nitpicks in the last patch and tested it manually to ensure it does what is expected.
Single image works as expected:
Change to unlimited images in field settings:
Before patch:
Patched:
Comment #124
Wim LeersWow, great work here!
The inner comment in the first branch actually applies to the second branch also.
So I think a cleaner/easier to understand solution would be what's in the attached patch.
Finally, doesn't this need to backported to Drupal 7?
Comment #125
alexpottSo do we have the same problem with the post rendering too?
Comment #126
star-szrYeah I'm unassigning, the render_children stuff has always just confused me, sorry for the delayed response. Will keep an eye on this issue though.
I will say it seems a bit risky for 8.1.x, we may want to bump to 8.2.x.
Comment #127
akalata CreditAttribution: akalata commentedI believe this bug is also causing issues where the file upload runs twice, creating two entries in file_managed table, both pointing to the same file. One fid is mapped to the field and marked permanent, the other is marked temporary. When file cleanup is triggered, the temporary fid's file is deleted -- which also deletes the file the permanent fid is pointing to. It's an annoyingly intermittent bug making it appear that files are deleted at random.
Comment #128
josmera01 CreditAttribution: josmera01 at Globant commentedThis patch to version 8.1.3, thank you.
Comment #129
enap CreditAttribution: enap commentedPatch from #128 working in 8.1.8.
Comment #130
MattDanger CreditAttribution: MattDanger at Socha Dev commentedPatch from #128 works nicely on 8.1.7 and 8.1.8 for file fields.
Comment #131
xjmI don't see an answer yet for #125, so marking NR for that.
Comment #132
xjm@akalata:
Whoa, that sounds like a critical issue. Thanks for pointing that out. Promoting for visibility to check whether that is the case. If it is, and this patch fixes it, we should add a test for that case too.
Comment #133
swentel CreditAttribution: swentel commentedHmm, I know of #2666700: User profile images unexpectedly deleted which describes that as well, but I haven't been able to reproduce this at all. I also think we'd be flooded with bug reports alike, and that hasn't been the case yet, unless users don't notice, but that seems unlikely. So my gut feeling is telling me that this duplicate wrapper wouldn't cause that, but better safe than sorry of course :)
Comment #134
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedOh, well ... #render_children continues to hunt me ...
#1920886: drupal_render() should check if it's rendering a 'render element' and if so call drupal_render_children() (inline) instead is the original issue for that. Bad if that is what creates the duplicate ajax wrapper.
Let me explain this a little, to give others a chance to see what _should_ happen here:
This happens when a render array tries to render itself to render its remaining fields:
e.g. consider a twig template like this called foo.html.twig a theme hook, called 'test_foo', which uses a render element of 'foo':
Now what happens is:
Now some code does:
Because of how 'render element' works, the whole render array becomes the 'foo' element.
So now drupal_render() [Renderer->render()] starts and sets #render_children => TRUE, which prevents an endless recursion.
So in theory, when '#render_children' is set, then drupal_render() should really only consider the children, e.g. 'baz' and 'bar', because that is what the calling code expects.
We tried to short circuit that by doing that case very early in the function, however somehow that failed some tests originally.
Maybe this works now, so that is what I would try first:
Likely the simplest to make this work with render_context + co is to just create a new array with _just_ the children and recursively call itself.
e.g.
Then return that.
Comment #135
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedLets try this most simple approach.
Comment #137
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedFixing test assumptions, which make sense.
Comment #138
xjmWell, there was #2725415: Text Editor module fails to track usage of images uploaded in text_with_summary fields, allows uploaded images to be deleted, but it was fixed awhile ago.
Comment #139
xjmI promoted #2666700: User profile images unexpectedly deleted to critical and am re-demoting this one. @akalata, could you follow up there, maybe help with steps to reproduce it? I have not been able to yet.
I also haven't been able to reproduce the original issue in the summary with the duplication of the message on user profile fields. I also can't reproduce the validation message being duplicated for images in general unless it's a mutlivalue field. However, I can reproduce it with a single-value non-image file field.
Comment #140
xjmComment #141
xjmComment #142
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedThe closed duplicate issue was triaged major, so this one should stay major as well.
However I think this solves it properly for all cases (finally!).
Comment #143
xjm@Fabianx, which duplicate?
Comment #144
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commented#1920886: drupal_render() should check if it's rendering a 'render element' and if so call drupal_render_children() (inline) instead I did close as duplicate.
Comment #145
seanrThis fixes for me.
Comment #147
deepakrmklm CreditAttribution: deepakrmklm at Zyxware Technologies commentedThis works for me.
Comment #149
lucastockmann CreditAttribution: lucastockmann at undpaul commentedIt seems that it's fixed in 8.2.x. Can anyone confirm that?
Beside that I think we should definitely bring this into 8.1.x. - I'm not that much into Drupal 8 release cycle, is that something we can do?
Comment #150
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThis is definitely still broken, patch needs a re-roll.
Comment #151
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #152
yogeshmpawarComment #153
yogeshmpawarHere is the rerolled the patch against 8.2.x
Comment #154
yogeshmpawarComment #156
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #157
lauriiiThe code fix itself looks good for me. I think we could improve the docs a little bit so it would be easier for someone just looking at the code to understand what's happening.
We could document here that #render_children is internal property and add a @see to the ThemeManager::render().
We should explain here why the #children is not empty sometimes.
This is rather confusing comment since render could be also called outside Twig template
Comment #158
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#157
1. Agree
2. Should only happen if a pre-process function is populating #children (no one in core does that), likely no reason for this except for tests and BC compatibility.
3. The wanted reasoning here is:
#render_children property is internal and hence will only be set from within the ThemeManager, which then most likely will use a twig template. Though indeed it could get messy ...
Maybe:
Hm, that should work: https://3v4l.org/dHiB1
Though it means the $elements is not updated with the result ...
However any other engine than twig should use drupal_render_children() anyway ...
So I guess overwriting the 'reference' should work and avoid accidentally changing the callers state, which in 99% of the cases won't use the changed $elements anyway.
Comment #159
lauriiiMade these changes for the patch. Thanks for the feedback @Fabianx
Comment #161
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedHm, those unit tests ...
We might need to populate at least #markup and #attached in the original array before returning ... (e.g. save $elements before).
Comment #162
lauriiiThis should fix the tests
Comment #163
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedNice, back to RTBC.
Comment #165
lauriiiThe test failures were unrelated to the change here
Comment #166
alexpottThe issue summary still needs updating as it hasn't been since the tag was added in #139. Also whilst it is great to see the implicit test coverage added on the file field level it'd be great to see some additional test coverage added in
Drupal\Tests\Core\Render\RendererTest
since the renderer is complex and unit test coverage really helps.Comment #167
lauriiiThanks @alexpott for your feedback. I will work on writing the additional unit test coverage for this.
Comment #168
lauriiiAdded some test coverage for both, unit and kernel tests.
Comment #169
Fabianx CreditAttribution: Fabianx as a volunteer commentedNew tests look great, back to RTBC.
Comment #171
xjm@Cottser, @alexpott, @lauriii, @joelpittet and I agreed that the current scope of the issue is a normal bug. Thanks everyone! Glad to see it RTBC. (Though it still hasn't had the issue summary update requested in #139 which makes it take longer to review).
Comment #172
xjmJust taking some notes -- none of this is blocking at the moment but wanted to document a few things I saw in the process of trying to review it.
The
#render_children
property is defined incore/lib/Drupal/Core/Render/Element/RenderElement.php
:So that all is documented correctly already.
This method did not actually fail on the test-only run; was it expected to?
behavior :)
I don't quite understand the last sentence in the first inline comment here.
Can we use a variable name that describes the purpose of
$original_elements
? The fact that they are "original" doesn't actually mean anything out of context.Also, my head nearly exploded trying to follow the array manipulation. :)
These changes are out of scope and should not be included in the patch.
Out of scope change.
Comment #173
alexpottIt's great to see unit tests added to just test the render system changes that are made.
I think each line needs to be commented here to explain what is occurring. We all need to point out that this is necessary because $elements is passed in by reference to doRender() and doRender() is recursive.
Before we can commit this patch we need to update the issue summary so that the actual problem and resolution is detailed.
Comment #174
lauriiiThanks for the review @xjm! I rewrote the documentation on the confusing part with some help from @alexpott. I also made other changes that was requested.
Comment #175
joelpittetSome minor bits and things from code. Just taking it for a tour. Assume all is good if I don't come back with any reports
The empty check can be nested in the else because it is only relevant there.
The $children variable as elsewhere in our codebase should be $children_keys because that is what we get back.
nit: don't need the comma before and because it's not in a series.
Comment #176
lauriiiSome further cleaning on this patch.
Comment #177
idimopoulos CreditAttribution: idimopoulos commentedI have tested this in Drupal 8.2 and it's working as expected. Nice work.
In UI, tests were done in single and multi cardinality and the behaviour was normal.
It works great in our project where we also use a custom theme. Error and success messages only show once.
Comment #178
alexpottI know this issue is still being discussed by @lauriii and @Fabianx and other theme maintainers so setting back to needs review and adding needs subsystem maintainer review.
It also really needs an issue summary update since the patch and the summary are not aligned since the problem is deep in the render system innards and not much to do with the file module.
Comment #179
Wim LeersYep, nothing to do with file field, everything to do with AJAX system. This also affects BigPipe, because it uses the AJAX system. See #2738685: BigPipe leaves wrapper <div>s in place, because AJAX system leaves them — this can cause some CSS to break. Should probably be mentioned in the updated IS as an example, file field is just another example.
Comment #180
Fabianx CreditAttribution: Fabianx as a volunteer commentedMaybe we should bring this back to #1920886: drupal_render() should check if it's rendering a 'render element' and if so call drupal_render_children() (inline) instead as that has the older history instead.
Still discussing somewhat with Laurii.
And I found out we can likely backport that to D7 with keeping BC.
Comment #181
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedWe've hit this one on a current project too and can confirm that duplicate_ajax_wrapper-2346893-176.patch fixes the issue for us!
I'll see if I can make a start on an issue summary update :)
Comment #182
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedComment #183
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedComment #184
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedComment #185
alexpottFor me the other thing to work out before this is RTBC is whether or not we should bubble up the cache and assets here:
I think everything is working atm because the render system is doing it automagically for us. At the very least we need a comment as to why we are only preserving the markup.
Comment #186
larowlanShouldn't this be
and not
CacheableMetadata::createFromRenderArray($elements['#cache']);
and if so, indicates we're missing test coverage for cacheability metadata bubbling with #render_children?Should we have a positive assert too, just to ensure that something is happening (a good habit to get into)?
Comment #187
larowlanAlso, that's some boss level issue summary updating Donna!
Comment #188
larowlanComment #189
Wim Leers#183+#184: that looks splendid! Except I realized that #179 is wrong, I confused this issue with #736066: ajax.js insert command sometimes wraps content in a div, potentially producing invalid HTML and other bugs, which also has been around for years. What I'm still missing in the IS, is a root cause analysis. I suspect this is it:
(Quoted from the current IS.)
#186.1 is absolutely right, that's wrong. NW for that.
Comment #190
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedThanks @Wim Leers!
So does that mean this has nothing to do with big pipe afterall?
Thanks @larowlan :-)
Comment #191
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedAdding this to the IS.
Is that something that could be done in a follow up?
This bug was RTBC before we released D8 and is impacting a site I'm working on right now. The patch fixes the issue we're having. If there are other problems that also need to be addressed, it might make sense to have a new issue that's not nearing the 200 comment mark to address those?
Speaking of follow-ups, I'll make one for the D7 backport now.
Thanks everyone! :-)
Comment #192
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedComment #193
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedComment #194
lauriiiAdded support for the cacheable metadata bubbling. I also fixed a bug where #access on the mainlevel wasn't being taken in account when rendering children. I also added test coverage for these things.
Comment #197
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedManual test #194 with simplytest.me - still works! :)
https://www.drupal.org/files/issues/duplicate_ajax_wrapper-2346893-194.p...
Comment #199
joelpittetRerolled
Comment #201
jasonawantAdding related issue: https://www.drupal.org/node/2745491. That issue's patch conflicts with this one in /core/modules/image/src/Tests/ImageFieldValidateTest.php.
Comment #202
SKAUGHTlinking. sounds similar to some IFE related issues
Comment #203
nod_loosely related
Comment #204
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedJust saw this again testing media!
Maybe time for a reroll and see if we can get this in?
pretty please?
Comment #205
lauriiiWe don't have to do the bubbleable metadata dance since we use
RenderContext::update
to apply the collected bubbleable metadata to the render array. I also added some more test coverage to asset handling in children render arrays since I couldn't find any pre-existing test coverage for that.Comment #206
Wim LeersThis is an API change. The IS says:
. We need a CR for this.Concern
Even though I am one of the people who worked the most on the Render API in Drupal 8:
#render_children
, so I can't say that I fully comprehend it, and therefore don't feel qualified to review the changes hereReview
So this is trying to deal with
'#render_children'
earlier. But I don't understand why yet. How does this break currently?We'll need a clear answer for somebody to RTBC this, but also for a core committer. I realize this is hard to explain, but that's exactly why we need to explain/document it clearly. If it isn't, risks are not understood well either, and it'll be RTBC for a very long time (because core committers are less likely to commit it).
I don't understand this at all.
$original_elements
is never used anywhere?These are clear.
s/since that …//
Comment #207
geovanni.conti CreditAttribution: geovanni.conti commentedHi.
Patch #205 works great for me.
Thanks!
Comment #208
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedI just got another bug report from a client about this one.
:(
What do we need to do to move this forward - looks like @Wim Leers did a pretty comprehensive review - is anyone able to address those points and do a re-roll?
At 208 comments this is getting pretty long in the tooth now. I'm happy to do anything within my power to help here, but I'm not sure how best to assist.
Comment #210
joseph.olstad*EDIT* deleted my own comment
Comment #211
osab CreditAttribution: osab as a volunteer and at AnyforSoft, Drupal Ukraine Community for Drupal Ukraine Community commentedHi! Patch #205 work properly on 8.3.6, thanks!
Comment #212
gnuschichten CreditAttribution: gnuschichten at ETECTURE GmbH commentedPatch #205 works fine on 8.3.5.
Comment #213
mathysp CreditAttribution: mathysp at Dazzle commentedPatch #205 works fine on D 8.3.7.
#206 still needs to be solved though.
Comment #214
Paladyn CreditAttribution: Paladyn commentedPatch #205 is not working for me.
Core 8.3.7, Webform 8.x-5.0-beta17, PHP 7.1.
Comment #215
divined CreditAttribution: divined commentedPatch 205 broke upload progress indicator (
Comment #216
gagarine CreditAttribution: gagarine as a volunteer commentedUsability is preferred over UX, D7UX, D8UX etc. See https://www.drupal.org/issue-tags/topic
Comment #217
rloos289 CreditAttribution: rloos289 commentedI found an issue with the patch where it was using the wrong array syntax. This small change fixes it.
Comment #218
cilefen CreditAttribution: cilefen commented@rloos289: Good idea. But please post an interdiff so we know what you changed.
Comment #220
tacituseu CreditAttribution: tacituseu commented#217 is a re-roll of #199, on top of that it is _removing_ short array syntax, #205 is the one to review.
Comment #221
josephdpurcell CreditAttribution: josephdpurcell at Digital Bridge Solutions commentedI can confirm I am experiencing this issue on Drupal 8.3.5.
I am uploading a patch that applies to the latest core 8.3.x branch (without tests) for use in particular for anyone with composer-patches.
Comment #223
josephdpurcell CreditAttribution: josephdpurcell at Digital Bridge Solutions commentedSetting back to needs review for #217. The patch from #221 should not be considered for this ticket, this ticket is for 8.5.
Comment #224
taggartj CreditAttribution: taggartj commentedhttps://www.drupal.org/files/issues/duplicate_ajax_wrapper_2346893-217.p...
Works for 8.3.7
Comment #225
darrenwh CreditAttribution: darrenwh as a volunteer and commentedHere is a rerolled patch for 8.4
Comment #227
darrenwh CreditAttribution: darrenwh as a volunteer and commentedLast patch was incorrect
Comment #228
ivan.chavarro CreditAttribution: ivan.chavarro at Globant commentedThe testing fails because the $elements['#markup'] is not an instance of Markup so I replaced it.
Comment #229
ivan.chavarro CreditAttribution: ivan.chavarro at Globant commentedComment #230
darrenwh CreditAttribution: darrenwh as a volunteer and at Investis Digital commentedLooks good
Comment #231
alexpottThe patch in #228 has no tests and seems to be very different from the patch in #205 and no-one has got to grips with @Wim Leers's review in #206.
Comment #232
alexpottI've merged the tests from #205 with the patch from #228. It seems that the tests all pass. Interesting because the amount changed in the Renderer is way way less. Which might mean this is way less risky.
Comment #233
alexpottWe can do a bit less work.
Comment #234
Viktor-T CreditAttribution: Viktor-T commentedTested the patch from #233, unfortunately still can see the duplicate AJAX wrapper around a file field.
If two or more elements on a page share the same ID, it can cause problems in screen readers which use IDs for labelling controls and table headings. This also causes problems in JavaScript methods like getElementById and querySelector, which behave inconsistently when duplicate IDs are present. Is it possible to change the ID so it is unique to each element?
Regards,
Viktor
Comment #235
alexpott@Viktor-T are you sure? I've tested the patch manually and the automated tests all show that there is not a duplicated wrapper. In order to test the patch I followed the steps in the issue summary. What exact steps did you follow and which wrapper ID do you think is duplicated?
Comment #236
Viktor-T CreditAttribution: Viktor-T commentedsorry about that, was not reading through the issue carefully enough. The described issue looks like solved. The issue I see on my side happening on a webform file field where I see the same double ajax-wrapper around the file field.
Comment #237
oriol_e9gWorks, with tests and #233 is the simplest solution.
Comment #238
tim.plunkettThe patch looks great!
This still is tagged for:
Setting to NW for those.
Comment #239
alexpottSo funnily enough the fix is the same as in #124. I made a comment about other render properties in #125 - it seems that that comment derailed the fix. Totally my fault but I was trying to do the right thing and have a complete fix. I think given that people are experiencing duplicate error messages we need to fix that problem in the simplest way possible. #233 is the simplest fix possible and we have good tests. Since the fix is small and restricted to only
#prefix
and#suffix
I don't think we need a change record because there is nothing for a developer or site owner to do as a result of the bugfix. Also sub system maintainer review is not required because this is just a small bug fix and not an API change. I've filed a followup to try to address the wider issues of what happens with#render_children
- #2926030: Fully test #render_children rendering and fix/find any bugs.Comment #240
oriol_e9gTotally agree.
Comment #242
Anonymous (not verified) CreditAttribution: Anonymous commented#241: #2926309: Random fail due to APCu not being able to allocate memory
Comment #243
heddnUpdated IS. I'm only seeing the symptoms if the cardinality is greater than 1. I've also run some manual testing and this does fix the issue. So +1 on RTBC.
Since this is a bug fix, I think can be backported to 8.4, yes? I've added a test run against that branch.
Comment #244
vagelis-prokopiou CreditAttribution: vagelis-prokopiou as a volunteer commentedAnother confirmation for the #233 patch. Working.
Comment #246
Wim LeersRandom fail due to DrupalCI infra problems (
apcu_store(): Unable to allocate memory for pool.
). Green again, so back to RTBC.Comment #248
Anonymous (not verified) CreditAttribution: Anonymous commentedAgain.
Comment #249
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedI can confirm patch #233 working fine.
Comment #251
tacituseu CreditAttribution: tacituseu commentedComment #253
tacituseu CreditAttribution: tacituseu commentedCI issues.
Comment #255
alexpottAnd yet more CI issues. Really hard to keep something rtbc at the moment.
Comment #257
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedComment #258
Tanvish Jha CreditAttribution: Tanvish Jha at Google Code-In commentedInterdiff created for two very recent patches.
Comment #259
larowlanAdding review credits for reviews that changed the shape of the patch
Comment #260
alexpottDiscussed this with @larowlan - we agreed to update the issue summary to be inline with the patch and ensure that the extra concerns (for example #125 and cache and asset bubbling are added to the follow-up, #2926030: Fully test #render_children rendering and fix/find any bugs. The follow-up contains all of this information so I'm removing all the remaining tasks because they've either been done or punted.
Comment #263
larowlanCommitted as f954875 and pushed to 8.5.x.
Cherry picked as 8e96f97 and pushed to 8.4.x.
Glad to see this resolved, let's continue in the follow-up #2926030: Fully test #render_children rendering and fix/find any bugs
Comment #264
dmsmidtGood job everybody!
Comment #265
Anonymous (not verified) CreditAttribution: Anonymous commentedNice news! Thanks everybody! 🚀
We can also strengthen the testing of duplication in/after #2809503: Convert AJAX part of \Drupal\file\Tests\FileFieldWidgetTest to JavascriptTestBase. Where we have JS-tests for uploading files. But while this issue in the PP-2.
Comment #266
kattekrab CreditAttribution: kattekrab at Catalyst IT for La Trobe University commentedFixed!!! Hooray!!! :) So happy to see this finaaaaalllly in!
Thanks everyone.
Comment #267
joseph.olstadkattekrab , can you please put a link to the followup issue noted here:
#2346893-191: Duplicate AJAX wrapper around a file field
standarrd naming convention for backport issues is
"D7 same title"
Comment #269
benjifisherHey Google, please index this: "drupal duplicate id ajax".
Comment #270
nassazI allow myself to intervene to say that this patch does not apply on the 8.4.5 version, I propose to correct the patch to apply it on this version. Thank you.
Comment #271
benjifisher@nasser.tijani: The reason the patch does not apply is that it has already been committed to the 8.4.5 version. Probably the patch will apply in reverse. (That would re-introduce the bug, so you would only want to do that for testing purposes.)
See the auto-generated comments #261 and #262 above.
Comment #272
Eunicia Estrocio CreditAttribution: Eunicia Estrocio at BrightLemon commentedPatch worked on 8.3.7, though now I have upgraded to 8.5.2 and no longer have to use this patch, as it's already fixed.
Good job everybody!