Tags: Fix null reference error in tags input on render (closes #23044)#23049
Tags: Fix null reference error in tags input on render (closes #23044)#23049AndyButland wants to merge 1 commit into
Conversation
|
Claude finished @AndyButland's task in 2m 6s —— View job PR ReviewTarget: Guards null references in Suggestions
Approved with Suggestions for improvementGood to go, but please carefully consider the importance of the suggestions. Labels applied: |
There was a problem hiding this comment.
Pull request overview
Fixes a runtime crash in the backoffice umb-tags-input web component by preventing updated() from dereferencing DOM queries that can be null (notably when the control is readonly and #main-tag isn’t rendered).
Changes:
- Added a guard in
UmbTagsInputElement.updated()to return early when#main-tagor#input-width-trackerisn’t available. - Documented why the guard is necessary (readonly rendering + transient re-renders).
Description
Fixes a
TypeError: Cannot read properties of null (reading 'style')thrown fromUmbTagsInputElement.updated()when rendering the tags input.The
updated()lifecycle hook unconditionally dereferenced the#main-tagand#input-width-trackerquery results:#main-tag(the "add tag" button) is only rendered when the control is not readonly —#renderAddButton()returnsnothingin readonly mode — so@query('#main-tag')resolves tonull. The query can also be transientlynullwhile the element re-renders, e.g. when navigating between two pages that both host a tags editor (the scenario in the issue, since tags are used on a shared composition across most pages). Becauseupdated()fires on every render, this surfaced as an error in the console.Fix
Guard the references before touching the elements:
Fixes #23044
Testing
I considered an automated unit test but it didn't feel like it added enough value to introduce a test class for what's just a guard.
To test manually, open up a couple of documents with a tags editor and navigate back and forth between them in the backoffice. Before I could clearly see the error, after the fix I don't.
Make sure adding and saving tags continues to work as expected.