Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Support for Server Rendering? #3

Closed
jaredpalmer opened this issue Apr 10, 2017 · 7 comments
Closed

Support for Server Rendering? #3

jaredpalmer opened this issue Apr 10, 2017 · 7 comments

Comments

@jaredpalmer
Copy link
Contributor

No description provided.

@RafalFilipek
Copy link
Owner

Hey @jaredpalmer!
This might be hard while DomHandler from htmlparser2 package is async. Maybe there is some other way to parse with DomHandler (I couldn't find any sync way).
Other option is to switch to different library. Perfect scenario:

  • synchronous parsing
  • smaller size
  • core node modules (like buffer) independent

@RafalFilipek
Copy link
Owner

@jaredpalmer checkout new 1.0.0 version. Should work with SSR :)
Let me know so I can close this issue.

@jaredpalmer
Copy link
Contributor Author

Yes!!!! YOU ARE AWESOME!

import convert from 'jsxfromhtml/lib/convert'
...

function myPage ({html}) => (
  <div>
    {convert(html, {}, '', '')} 
  </div>
)

@RafalFilipek
Copy link
Owner

@jaredpalmer hmmm, why are you not using <JSXFromHTML /> component :) ?

@jaredpalmer
Copy link
Contributor Author

Because https://github.com/RafalFilipek/jsxfromhtml/blob/master/src/index.js#L42 componentDidMount does not get called when you use ReactDOMServer.renderToString.

@jaredpalmer
Copy link
Contributor Author

Also there is a weird issue with how you are declaring you module for npm. I use webpack on both server and client, and use ["babel-preset-env", { "modules: false" }] and also flow-syntax and strip-types on my own project. However, I get this error:

./~/jsxfromhtml/src/index.js
Module parse failed: /Users/jared/workspace/github/xxxxx/node_modules/jsxfromhtml/src/index.js Unexpected token (7:5)
You may need an appropriate loader to handle this file type.
| import convert from './convert';
| 
| type Props = {
|   html: string,
|   mapElements?: { [key: string]: any },
 @ ./common/screens/WP/Page.js 20:0-38
 @ ./common/routes.js
 @ ./client/Root.js
 @ ./client/index.js
 @ multi ./~/react-hot-loader/patch.js (webpack)-dev-server/client?http://0.0.0.0:5001 (webpack)/hot/dev-server.js ./client/index.js

If i comment out these lines from the package.json, everything works fine.

"module": "src/index.js",
  "jsnext:main": "src/index.js",

Thoughts?

@RafalFilipek
Copy link
Owner

Ad. SSR:
@jaredpalmer ohhh, right. Check this issue #4 out and let me now.

Ad. second problem ... looks like you have to parse jsxfromhtml with babel while webpack is looking for es6 code when module , jsnext:main is set. I'll create new issue for that and look at it ASAP.

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

No branches or pull requests

2 participants