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

Using same version of preact for pre-rendering #803

Merged
merged 5 commits into from
May 28, 2019

Conversation

prateekbh
Copy link
Member

@prateekbh prateekbh commented May 20, 2019

Fixes #795

What kind of change does this PR introduce?
Fixes duplicate preact problem.

  • Uses preact . and preact-render-to-string from user land.
  • Fall back to local preact-render-to-string to local copy but wont work with preact-X
  • Note: After this we need to include preact-render-to-string in all our template's package.json

Did you add tests for your changes?
Already exist

Does this PR introduce a breaking change?
No

@prateekbh prateekbh requested a review from lukeed May 20, 2019 15:45
@hassanbazzi
Copy link
Member

Maybe we should add a note on that somewhere in the FAQ maybe? or Readme?

@prateekbh
Copy link
Member Author

about the comments i added?

@hassanbazzi
Copy link
Member

Well..... For users. I think users will expect the user-land preact to affect pre-rendering Preact.

@prateekbh
Copy link
Member Author

@hassanbazzi I updated the PR to use modules from user land instead its just that it has an added step of installing preact-render-to-string in user land

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you so much for picking this one up 👍🎉 Maybe we can add a test on top of the changes to make sure we don't regress here in any future versions 💯

@ForsakenHarmony
Copy link
Member

Not entirely sure how to write a test for it

@ForsakenHarmony ForsakenHarmony merged commit 8f8f655 into master May 28, 2019
@ForsakenHarmony ForsakenHarmony deleted the fix-for-x-options branch May 28, 2019 18:39
ForsakenHarmony added a commit that referenced this pull request May 28, 2019
@ForsakenHarmony ForsakenHarmony restored the fix-for-x-options branch May 28, 2019 19:51
@prateekbh
Copy link
Member Author

:| this was breaking the current tests....
i'll add the fix for tests ASAP

@ForsakenHarmony
Copy link
Member

I already have it

@ForsakenHarmony ForsakenHarmony mentioned this pull request May 28, 2019

let preact = require('preact'),
renderToString = require('preact-render-to-string');
const preact = require(require.resolve(`${cwd}/node_modules/preact`));
Copy link

@tomsiwik tomsiwik Mar 6, 2020

Choose a reason for hiding this comment

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

Currently, using a monorepo manager like lerna this workaround breaks the build process and returns:

✖ ERROR Template execution failed: Error: Cannot find module './node_modules/preact'

The cwd is located inside root/packages/mypack and is looking for a root/packages/mypack/node_modules, which however is located in root/node_modules. Node won't resolve correctly due to lernas or yarns module mgmt and thus this will break.

I reverted the changes and logged destination. A revert worked but I think changing the destination to: ${__dirname}/../../../../preact and ${__dirname}/../../../../preact-render-to-string would work too.

Not sure what's more elegant...

Copy link

Choose a reason for hiding this comment

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

is there any workaround for this? I just moved a preact app into my monorepo to not have to maintain it in a separate repo, and I'm running into this exact error.

Copy link

@tomsiwik tomsiwik Aug 27, 2020

Choose a reason for hiding this comment

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

@alexjsdev With Lerna and Yarn workspaces no. If you disable yarn workspaces this should work with Lerna though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in #1418

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

Successfully merging this pull request may close these issues.

Duplicate preact instance while prerendering breaking options
7 participants