threepointone / rakt

fast websites, by default
291 stars 12 forks source link

Initial feedback #6

Open fionawhim opened 7 years ago

fionawhim commented 7 years ago

By hacking cli.js to take an argument I was able to get the development version of an app I'm building on Next.js working with rakt. You can see the branch here: https://github.com/CityOfBoston/311/tree/rakt

“Bugs”

Overall Feedback This is very exciting for me. If you look at my commit adopting rakt I was able to clear out an entire GraphQL setup that was just there to communicate between my server and client (I’d rather over-do a GraphQL server than deal with REST endpoints at this point, though.)

While the rakt command was neat for starters, I expect that I’d want to have my own server startup and integrate rakt as middleware or a handler. That would let me handle config, logging, and any other extra things that I wouldn’t expect or want rakt to handle.

I’m nervous of the way the rakt babel plugin searches for components that match react-router names. I’d be willing to put up with a little more boilerplate in defining Route render methods in order to feel like there was less magic there. I understand if that’s not feasible, however.

Specific Feedback I’ll want to do dependency injection to get data-providers into my @initial blocks (rather than require singletons). This could be achieved by putting in my own middleware that attaches objects to the req, though it might be nicer to provide a function that rakt will call for every request that returns a “context” object that’s passed to @initial blocks.

Making the <Route> matched params available to the @initial blocks in some way would be helpful, especially for RESTful URLs that do a lot in the path. That way the code in @initial doesn’t have to re-parse the URL, which could get out-of-sync with the react-router matching.

I’d be interested if rakt didn’t require glamor or react-helmet, and had hooks for me to choose those or not as appropriate.

Thanks! Let me know how I can help. I’m particularly interested in how to integrate this with an existing server and also how to get the initial SSR rendering to include the fetched data.

threepointone commented 7 years ago
@middleware(({req, res, next}) => {
  req.random = Math.random()
})
class App extends React.Component {
  render() {
    return <div>
      my app!
    </div>
  }
}

We could parse this out like we do initial calls, and set it up in the server that we start up. Then, every @initial component's req has access to req.random.

(Similarly, I'm thinking of a @setup(app => {...} directive, that'll be run only once when the server starts up.)

nb: so, thank you for the bugs :) the code is still pre-alpha really, mostly a POC to prove that the damn idea is possible. hence all the shortcuts and bugs. I do plan on making this 'prod-ready' though, and appreciate the help! I'll make issues for the 'tasks' I see coming up in the next few days, will ping when it's substantial.

apnerve commented 5 years ago

Was this the inspiration for nextJS?