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

Plugins relying on module hijacking won't load. #2866

Merged
merged 17 commits into from
May 15, 2018

Conversation

tjwelde
Copy link
Contributor

@tjwelde tjwelde commented Apr 18, 2018

While investigating, why hyperline doesn't work in hyper2, I found out, that the main process requires the plugin too. Unfortunately it doesn't hijack common modules, as the renderer does, so it fails.

So, with this PR modules loading is also hijacked on the main process, so that plugins can load.

Problems I see:

case 'hyper/Notification':
case 'hyper/notify':
case 'hyper/decorate':

all return just Object here, because they can not just be required, since they work differently on the main process, than on the renderer. I don't really know, how to solve this, or even if solving that would be needed.

Also the app/plugins.js file is required from the renderer process, but returns a cached copy, so the code doesn't get executed again, but it is still smelly. Especially having the module hijacking twice in the code. Any ideas here?

@timothyis timothyis requested a review from chabou April 18, 2018 15:42
@chabou chabou changed the base branch from master to canary April 20, 2018 14:45
@chabou chabou changed the base branch from canary to master April 20, 2018 14:47
@chabou
Copy link
Contributor

chabou commented Apr 20, 2018

Thank you so much to have analyzed this issue.

I have no problem to have some copy/paste and some duplicate code.

But 2 things should be improved:

  • Adding some comments in both places to ask contributors to update both.
  • Can you create your feature branch from our canary branch and not master branch?

Copy link
Contributor

@chabou chabou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some improvements are needed

@chabou chabou added this to the 2.1.0 milestone Apr 20, 2018
@Stanzilla Stanzilla added the 👀 Awaiting Response Issue or PR is awaiting a response from the author label Apr 24, 2018
@tjwelde
Copy link
Contributor Author

tjwelde commented May 2, 2018

Ok, I will work on it, when I have some free time. I did base this PR against master, since it felt more like a hotfix to me, but I can still base it against canary, if you want to.

@chabou
Copy link
Contributor

chabou commented May 2, 2018

Yes please, every PR should target canary wand will be eventually cherry-picked to master if it can't wait for a normal release cicle: canary -> master

@tjwelde tjwelde changed the base branch from master to canary May 3, 2018 10:11
@tjwelde tjwelde force-pushed the hotfix/module_load-hijacking branch from 15c44fe to 35d50eb Compare May 3, 2018 10:31
@tjwelde
Copy link
Contributor Author

tjwelde commented May 3, 2018

@chabou please review again

@tjwelde
Copy link
Contributor Author

tjwelde commented May 8, 2018

Or maybe @Stanzilla ?

Copy link
Contributor

@albinekb albinekb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@chabou
Copy link
Contributor

chabou commented May 8, 2018

Sorry for the delay

@chabou
Copy link
Contributor

chabou commented May 8, 2018

I'll test it ASAP

@chabou chabou merged commit f75895a into vercel:canary May 15, 2018
@chabou
Copy link
Contributor

chabou commented May 15, 2018

Nice work @tjwelde!
Thank you so much 🙏

@sahilchaddha
Copy link

sahilchaddha commented May 20, 2018

Hi @tjwelde ,
Running these changes gives error "Cannot find module react" after running yarn run dist . The Mac .app returns error.
screen shot 2018-05-20 at 3 59 03 pm

Commenting the code for patchModuleLoad(); works well. But with these changes it does not.

@tjwelde
Copy link
Contributor Author

tjwelde commented May 20, 2018

Hmm, yes you're right. React is placed in the root node_modules, which apparently doesn't get added into the build file. Reading into this it turns out electron-builder is only including files from the app directory and before we execute build, we compile lib into app/renderer/bundle.js.

So, we either add react and react-dom also to app/package.json, or we decouple "frontend hooks" from "backend hooks" at the plugin side, e.g. we have two entry points in a plugin, one for the Electron hooks, one for the Renderer hooks.

What do you say @chabou ?

@chabou
Copy link
Contributor

chabou commented May 29, 2018

I can't imagine a case where a plugin needs react or react-dom in the main process.
I would suggest returning an Object for these imports too.

Any case, splitting plugins is not an option, imo.

@tjwelde
Copy link
Contributor Author

tjwelde commented May 29, 2018

I tried that before, but unfortunately it breaks the plugin at the loading stage.
I think it is weird to load everything a plugin needs for the frontend, while only wanting to load the backend code.

@chabou
Copy link
Contributor

chabou commented May 29, 2018

Ok, I reproduced, and this is due to styled-jsx:
TypeError: Super expression must either be null or a function, not undefined at exports.default (/Users/chabou/Documents/Projets/hyper/.hyper_plugins/local/hyperline/node_modules/styled-jsx/node_modules/babel-runtime/helpers/inherits.js:21:11)

I think that we don't have to hijack react and react-dom import on the main process side.
Removing these imports and returning Object for hyper/component did the trick for me.

@tjwelde
Copy link
Contributor Author

tjwelde commented May 29, 2018

I tried your proposed solution, but it doesn't work after running yarn run dist.
I guess it is that way, since while developing, hyperline is located in a subdirectory of hyper and therefore has access to hypers node_modules. It doesn't have that in the build, since hyperline is located in the users home directory in that case.

chabou added a commit to chabou/hyper that referenced this pull request Jun 4, 2018
Regression was introduced by vercel#2866. Release version of Hyper failed to start.
Requiring react(-dom) in main process makes no sense.
@chabou chabou mentioned this pull request Jun 4, 2018
@chabou
Copy link
Contributor

chabou commented Jun 4, 2018

@tjwelde It definitely works (don't forget to remove react(-dom) requires).

I made #3067. Please discuss there about how to fix this regression.
We need to fix it quickly because we can't release anymore.

chabou added a commit that referenced this pull request Jun 11, 2018
Regression was introduced by #2866. Release version of Hyper failed to start.
chabou pushed a commit that referenced this pull request Dec 15, 2018
Fixes some plugin loading (like hyperline)
chabou added a commit that referenced this pull request Dec 15, 2018
Regression was introduced by #2866. Release version of Hyper failed to start.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 Awaiting Response Issue or PR is awaiting a response from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants