SharePoint / SharePoint/sp-dev-docs
Issue with two separate ListView Command Set extensions in List WebPart
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 1.4k
- Forks
- 1.1k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 12
Description
Description
I observed a strange behavior with Command Set extensions in a (standard) List WebPart.
If you are using two different CSEs on a list, it works perfectly fine on the list itself. But if that list is embedded in a (standard) List WebPart, the buttons won't render most of the time. Sometimes it only renders one button (CSE A), but not the other (CSE B).
After some digging I realized that CSE A registers an async method on the listViewStateChangedEvent.
private _onListViewStateChanged = async (args: ListViewStateChangedEventArgs): Promise<void>
CSE B does register a normal method (because it doesn't need it). The funny thing: the event still triggers and sets the button to visible, but the button won't render. And yes, I do call this.raiseOnChange();
private _onListViewStateChanged = (args: ListViewStateChangedEventArgs): void
After making that one also async, it worked perfectly fine.
Steps to reproduce
- Deploy two ListView Command Set extensions, one with an async _onListViewStateChanged method and one as a default _onListViewStateChanged method. Set the initial button visibility for both to false. Set the buttons to visible in the event if 1 or more items have been selected.
- Embed the list in default SharePoint List WebPart on any page
- Refresh the site. Most of the time you won't see any button after selecting item(s). Sometimes only the one with an async event.
- Hard Refresh the site, you will see both buttons
- If you soft refresh again and you will see the same problem as in step 4
- Change the second _onListViewStateChanged to an async
- Works perfectly fine now
Expected behavior
Setting a button to visible should make it visible, no matter if the event is registered as an async or not
Actual behavior
Button visibility property will be set to visible, but it won't render at all.
CLI version
1.22.1
Node.js version
v22.19.0
Operating system
Windows
Template (if applicable)
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with two ListView Command Set extensions embedded in a standard List WebPart, using _onListViewStateChanged with one async and one normal handler. Inspect how listViewStateChangedEvent and raiseOnChange() update and render button visibility. Done means both buttons render consistently after selection and refresh regardless of whether the handlers are async.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100