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

Can't implement registered custom Handlebars helpers anywhere. #594

Closed
mkgy opened this issue Dec 3, 2020 · 15 comments
Closed

Can't implement registered custom Handlebars helpers anywhere. #594

mkgy opened this issue Dec 3, 2020 · 15 comments
Assignees
Labels
bug Something isn't working v4 version 4

Comments

@mkgy
Copy link

mkgy commented Dec 3, 2020

!! Check existing issues before logging new ones !!

Version used
feature/v4

Describe the bug
search-extensibility-demo has a default custom Hundlebar helper called 'myHelper'. When I try to call it on some values in searchResults I get the message "Error: Missing helper: "myHelper".

To Reproduce
Steps to reproduce the behavior:

  1. Clone feature/v4 branch
  2. Navigate to folder search-extensibility
  3. run npm i
  4. run gulp bundle
  5. run npm link
  6. Navigate to folder search-extensibility-demo
  7. run npm i
  8. run npm link @pnp/modern-search-extensibility
  9. run gulp bundle
  10. run gulp bundle --ship
  11. run gulp package --ship
  12. add the solution to the global catalog
  13. select the checkbox "Make this solution available to all sites in the organization"
  14. register my manifest ID in the target Web Part instance
  15. add a column for the details list layout
  16. make adjustment to column value by implementing the default custom Handlebars helper "myHelper"

Expected behavior
By definition "myHelper" should convert a string-value to lowercase.

Screenshots

image
image
image
image

Desktop (please complete the following information):

  • Browser : chrome, edge

Additional context
none

@FranckyC
Copy link
Collaborator

FranckyC commented Dec 4, 2020

Hi @mkgy, can you try with parenthesis {{myHelper (slot @root.slots.Language)}}. I'm not able to reproduce this issue :(. Also, please try with the latest v4 branch code. We had some issues with latest commits so it may explain.

@mkgy
Copy link
Author

mkgy commented Dec 7, 2020

I have tried with the latest v4 branch code and also used the syntaxes {{myHelper (slot @root.slots.Language)}} and {{myHelper slot @root.slots.Language}}
However, the problem still remains, namely that helper is missing.

@mkgy
Copy link
Author

mkgy commented Dec 7, 2020

I have created a new SharePoint Framework project of type 'Library' with yo @microsoft/sharepoint. I linked it with the @pnp/modern-search-extensibility library. In the main entry point, I implemented the IExtensibilityLibrary interface and provided the necessary methods returning empty arrays for those extensions that I don't need now. Inside the method registerHandlebarsCustomization() I registered my own custom Handlebars helper called "iliToUpper". Then I called this method from Column value (under "Managed columns")using {{iliToUpper (slot item @root.slots.Language)}}.
Similarly I called the custom helper "myHelper" from search-extensibility-demo using {{myHelper (slot item @root.slots.Language)}}
I have registered the GUID of both extension libraries in my web part and saved it.
In the screenshoot below you can see the outcomes of the method calls under the columns iLiHelper and MyHelper respectively.

It seems neither the demo extensibility library nor my own extensibility library is working properly. Hence, it is not possible to call a custom Handlebars helper on a value.

****Screenshot ****
image

@FranckyC
Copy link
Collaborator

FranckyC commented Dec 7, 2020

What if you use the helper in the main template instead of a column? Does it work?

@FranckyC
Copy link
Collaborator

@mkgy Ok I think I know what is going on. You are probably using the v3 search results Web Part and not the v4...I tried to run your scenario from scratch and it works fine. Make sure you selected "PnP - Search Results" Web Part and not "Search Results". These are not the same. Let me know.

@FranckyC
Copy link
Collaborator

@mkgy Ok I think I know what is going on. You are probably using the v3 search results Web Part and not the v4...I tried to run your scenario from scratch and it works fine. Make sure you selected "PnP - Search Results" Web Part and not "Search Results". These are not the same. Let me know.

Ok nevermind, I thought according to the first screenshot it was the v3 due to the default sortable "Title" column but the scond screenshot looks like v4. @wobba @MakingThingsWorkToronto can you try to deploy and use the extensibility demo project. I'm not able to reproduce this issue.

@wobba wobba self-assigned this Dec 15, 2020
@wobba wobba added the Needs: Triage Needs investigation and repro label Dec 15, 2020
@mkgy
Copy link
Author

mkgy commented Dec 16, 2020

@FranckyC I put your suggestion into practice and it seems to work fine.
I did the following:

For webpart "General results"

  1. select layout "Custom"
  2. select layout option "
  3. inside this template create a div with an orange background
  4. call the custom Handlebars.js helper "myHelper" from within this div as follows:
    {{ myHelper (slot item @root.slots.Language)}}

    image

Note: the slot 'Language' is already added to Layout slots.
image
Also the value of this slot is activated
image

Outcome of "General results": This worked fine as you can see in the below screenshot ***:

screenshot***
image

@mkgy
Copy link
Author

mkgy commented Dec 16, 2020

The problem arises when I want to call the Handlebars.js halper from the Manage columns of template "Detail List"

For webpart "Titles"
1.select layout "Details List"
2.select layout option "Manage columns"
image
3.Edit handlebars expression to {{ myHelper (slot item @root.slots.Language)}}
image

Note: the slot 'Language' is already added to Layout slots.
image
Also the value of this slot is activated
image

Outcome of "Titles":
image

@tripleseven73
Copy link

tripleseven73 commented Mar 21, 2021

I ran into the same "Error: Missing helper: ..." problem and discovered it is caused by adding .a "PnP - Search Filters" Web Part to the page.

Steps to reproduce:

  • add new blank modern site page
  • optional: add two columns section layout
  • add PnP Search Results Web Part (to left column of two columns section)
  • configure PnP Search Results Web Part to the point that it is displaying results using detail list
  • add manifest ID of custom handlebar library to PnP Search Results Web Part
  • add column to detail list using a handlebar helper of custom handlebar library
  • publish the page
  • hit CTRL + F5 for full refresh
  • verify handlebar helper is working
  • add PnP Search Filters Web Part (to right column of two columns section)
  • publish the page without configuring / connecting Search Filters Web Part
  • hit CTRL + F5 for full refresh
  • Search Results Web Part is displaying "Error: Missing helper: ..." in column using custom handlebar helper
  • remove Search Filters Web Part
  • publish the page
  • hit CTRL + F5 for full refresh
  • custom handlebar helper in Search Results Web Part is again working as expected

Behavior observed on several pages in SP Online using PnP Modern Search 4.1.0 (March 2021)(latest version as of moment of writing).

Update:
In a site page with two Search Result Web Parts and one Search Filter Web Part, the "Error: Missing helper: ..." can be resolved by dragging the Search Filters Web Part to a different location on the page (e.g. by dragging is to the bottom of the page).

@wobba wobba added the v4 version 4 label Mar 27, 2021
@ayblanchet
Copy link

Hi,

I confirm, I still have the same error "Error: Missing helper" with or without searchFilters. It's impossible to use custom helper.
The extends librairy is correctly load, but the helper is not recover.

@wobba wobba added the bug Something isn't working label May 4, 2021
@wobba
Copy link
Collaborator

wobba commented May 24, 2021

@tripleseven73 I can repro and think it's related to web parts perhaps having the same handlebar instance/service key. @FranckyC do you have any ideas? Seems the web components are not getting the correct instance when running this._serviceScope.consume<ITemplateService>(TemplateService.ServiceKey); as the instance is missing the registered helpers.

@wobba wobba removed the Needs: Triage Needs investigation and repro label May 24, 2021
wobba added a commit that referenced this issue May 24, 2021
@wobba
Copy link
Collaborator

wobba commented May 24, 2021

Fixed it by rearranging some code to ensure loading sequence is not causing race conditions :)

@wobba wobba closed this as completed May 24, 2021
@wobba wobba reopened this May 25, 2021
@wobba
Copy link
Collaborator

wobba commented May 25, 2021

Seems still an issue, just triggers less :(

wobba added a commit that referenced this issue May 27, 2021
@wobba
Copy link
Collaborator

wobba commented May 27, 2021

Added a hack workaround for now. Weird stuff.

@wobba wobba closed this as completed May 27, 2021
FranckyC added a commit that referenced this issue Jun 23, 2021
…ect. Fixed by creating an array of scope refrences for the Web Part currently displaying the component.
@FranckyC
Copy link
Collaborator

Found the root cause. Should be OK for the next release.

wobba added a commit that referenced this issue Jun 24, 2021
Fixed #594 - Wrong service scope  in web components
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v4 version 4
Projects
None yet
Development

No branches or pull requests

5 participants