Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebPartTitle Control Fails to Update After Initial Save #1877

Open
ferrarirosso opened this issue Sep 2, 2024 · 10 comments
Open

WebPartTitle Control Fails to Update After Initial Save #1877

ferrarirosso opened this issue Sep 2, 2024 · 10 comments
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.
Milestone

Comments

@ferrarirosso
Copy link

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

v3.19.0

Affects also previous versions.

Expected Behavior

The WebPart title should be editable every time the WebPart is in edit mode, not just during the initial setup.

Observed Behavior

  • The WebPart title can only be set once, during the initial addition of the WebPart.
  • The event appears to propagate correctly, but the WebPart does not re-render, leading to the observed faulty behavior.
  • Note: Users have reported that this faulty behavior started appearing a couple of days ago.
  • Forcing a re-render by adding this.render() resolves the issue, but this would require updating all existing components. Additionally, this requirement is not documented as mandatory.

updateProperty: (value: string) => { this.properties.title = value; this.render(); }}

Steps to Reproduce:

  1. Scaffold a new SPFx React solution using SPFx v1.19.0.
  2. Ensure you are using Node.js v18.19.1.
  3. Implement the WebPartTitle Control as per the PnP WebPartTitle documentation.
  4. Add the WebPart to a SharePoint page.
  5. Publish the page.
  6. Edit the page and attempt to update the WebPart title.
@ferrarirosso
Copy link
Author

I have investigated the problem further

The issue arises from this commit #1672

The problem lies in the fact that changing the textarea element to use value instead of defaultValue makes it a controlled component in React.
Screenshot 2024-09-12 at 14 01 54

Please refer to the React documentation on React Js Uncontrolled Components - Default values

Since this change breaks production code and would require modifications to all solutions using the WebPartTitle component, I would suggest reverting this change. I am not sure of the original intent behind changing this in relation to Issue #1672.

Please advise if I should proceed with this change

@ferrarirosso
Copy link
Author

Any news here ?
@AJIXuMuK

@stefan-at-ilionx
Copy link

We're experiencing the same issue. We can't update beyond 3.16.2 because of this.

@joelfmrodrigues
Copy link
Collaborator

@t0mgerman, is there any chance you could help us get a better understanding of why the change was done a while back as you seem to have created the PR? I know it was a while back and it's hard to remember/review, which is why I am reaching out to you as I went through the PR details but was not sure why this was done. It seemed to me that you were trying to standardise the use of the value and defaultValue properties across different controls, but I could be wrong.

@t0mgerman
Copy link

@joelfmrodrigues We have experienced some issues after these changes were merged too, so I can only hold my hands up there and apologise! 😔

I think that was sort of my intention, but I don't actually recall any need to modify the WebPartTitle component - I think that may have been a change made in error.

The goal of the offending commit was to firstly start an implementation of client-side formula validation in the DynamicForm component - but in doing so, to also try and make better sense of the use of properties like value and defaultValue in the DynamicForm and DynamicField components, as there were at times not just those properties but changedValue etc. Sometimes a defaultValue property would be used against a value prop for a control and things like that. So it seemed a bit messy / inconsistent. I suspect I've changed things in the WebPartTitle component by mistake while making those changes and I've not spotted the above issue as I principally tested the DynamicForm component before submitting a PR.

I've found other problems with the implementation that I wanted to redress, but I need to get my dev branch up to date locally and understand what fixes have been made since.

@joelfmrodrigues
Copy link
Collaborator

@t0mgerman absolutely no need to apologise! Any contributions are welcome and we are all doing this in our own free time so no finger-pointing when there are issues 😊 I will merge the PR for this issue then.
If you need any help with getting your local branch up to date feel free to reach out to us. There is a relatively new sync option on GitHub that can sync your fork with the main repo and then you can just sync locally with your fork version, which makes things fairly simpler for most scenarios.

joelfmrodrigues added a commit that referenced this issue Dec 11, 2024
…control-fails-to-update-after-initial-save

Fix #1877: WebPartTitle Control Fails to Update After Initial Save
@joelfmrodrigues joelfmrodrigues added the status:fixed-next-drop Issue will be fixed in upcoming release. label Dec 11, 2024
@joelfmrodrigues joelfmrodrigues added this to the 3.21.0 milestone Dec 11, 2024
@joelfmrodrigues
Copy link
Collaborator

Hey @ferrarirosso thanks for reporting this, the PR to fix this issue is now merged. If you have the chance to test the beta release, please let us know if the issue has been fixed.

@ferrarirosso
Copy link
Author

will check it later and give you my feedback

@ferrarirosso
Copy link
Author

ferrarirosso commented Dec 11, 2024

  • Tested current WP which doesn't work
  • npm i @pnp/[email protected]
  • Tested again, it works !

It's Christmas soon 🎅

Thanks @joelfmrodrigues

@joelfmrodrigues
Copy link
Collaborator

@ferrarirosso many thanks for confirming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.
Projects
None yet
Development

No branches or pull requests

4 participants