Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Knockout web part with properties fails when running in SharePoint #233
Thank you for reporting an issue or suggesting an enhancement. We appreciate your feedback - to help the team to understand your needs, please complete the below template to ensure we have the necessary details to assist you.
Expected or Desired Behavior
That after building a new project based on the knockout template you should be able to run it in the Workbench within SharePoint.
When running in the local workbench, web part renders and custom properties are fine. When running in the Workbench in SharePoint, errors are logged below the web part. With a new, untouched project this is "Cannot read property 'description' of undefined".
Steps to Reproduce
Yo a new project using knockout, (fix the _description bug), and run it in the Workbench in a SharePoint dev tenant.
From: Pat Miller [mailto:email@example.com]
This is fixed in the next drop. For now, you can replace the _description variable in the generated code with _koDescription, and that will fix the issue.
OK, picking up on this. The first issue is that the this.properties does not exist in the constructor, as we have not yet deserialized them. We added an extra step here to handle issues around persisted data schema drift (version 2 of the webpart expects data in a different format, so we need to give the developer a change to fix up the data that they were handed).
The right place to do most of this is in onInit. However, for some reason the compontentElement doesn't have the template HTML in it when it is being set. I'm not exactly a knockout expert, so having a bit of difficulty sorting out what the issue here is.
At any rate, to move to the next step, pull everything out of the constructor after
OK, more information. Here's the workaround, as well as what the underlying bug is.
The underlying issue for why onInit() isn't working is that there is logic to handle onInit() taking too long that involves modifying the DOM to show a spinner. The spinner is supposed to be an overlay that is cleared, but currently is deletes the contents of the DOM, which wipes out the knockout stuff. So for now, do this:
0 - Update your constructor to look like this
1 - Create a new function
2 - Update your Render method to look like this