Open michaelmaillot opened 2 months ago
My suggestion is you do a PR with changes needed to get this working :)
That was my further request, but I just wanted to get an approval first 😄
You can assign this to me if there's such process in the repo.
Version used Ex: 4.13.1
Describe the bug
The current implementation of SPFx Library Component consumption doesn't allow to have more than one exported class.
If the main index.ts file exports something else than the class which implements the
IExtensibilityLibrary
interface, it won't be loaded by the extensibility service.To Reproduce Detailed steps to reproduce the behavior:
IExtensibilityLibrary
interfaceExpected behavior
Web Component should be loaded and displayed in the PnP Modern Search - Search Results webpart
Desktop (please complete the following information):
Additional context
First: a huge THANK YOU for this extensibility feature, it allows us (developers) to enhance PnP Modern Search properly without having to inject unsafe JS code! Kudos to the team!
After digging a bit into the Extensibility service, I think I know why it fails. It seems that the
loadExtensibilityLibraries
method (in the ExtensibilityService.ts file) doesn't check if the loaded exported module is defined during the parsing. As it goes through all the exported modules and as there's more than one, it crashes during the prototype methods check, resulting into not importing the expected module.My suggestion is to update the code here like this:
Like this, we also check if the current
extensibilityLibraryPrototype
in the filter array returns an object during the cast and if not, it will go the next occurence but in the end, it will load the one declared as expected in the library component.This will allow to leverage library components at its best to centralize reusable React components, shared third-party libraries and custom Web Components.