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

Is it ok to Import libraries like SortableJs directly into Renderer? or should it be done through preload as well? #135

Open
GitMurf opened this issue Jan 22, 2023 · 2 comments

Comments

@GitMurf
Copy link

GitMurf commented Jan 22, 2023

As the title state, I have had this question for a long time and still haven't gotten a clear understanding of the "best practice" answer... is it ok to import third party libraries like SortableJS (https://github.com/SortableJS/Sortable) via npm install and then Import directly into my renderer (index.js)?

Or instead should we be doing all the importing of third party libraries into the preload.js and then add to the context bridge API ways to grab the imported libraries (like Sortable in my case)?

@GitMurf
Copy link
Author

GitMurf commented Jan 22, 2023

As a follow-up to this, I still do not understand why require() is not allowed in renderer (index.js) but we can still use Import to bring npm packages into the renderer process? It would seem then that using Import is just a workaround to avoid the limitation that require() cannot be used. I believe I am misunderstanding something here so feel free to correct anything I have said that may be incorrect :)

@reZach
Copy link
Owner

reZach commented Nov 3, 2023

Hi @GitMurf. Thanks for being so patient, life has been very busy for me.

Any library/dependency that interacts with the operating system (eg. files, sounds, permissions) should be handled in the main process. This is done in order that a bad client/actor can't manipulate the front-end of your app to maliciously affect the underlying computer running the Electron app. Any UI app or framework as you mention like Sortable is okay to be in the renderer as it's just a UI component and isn't directly (or shouldn't be) referencing or manipulating data directly from the underlying computer running the Electron app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants