question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

example implementation for server side rendering?

See original GitHub issue

Hi! First, thanks for your tremendously awesome work on this ecosystem. I’ve been using next.js for two days now and for the most part everything just works. Very impressive given all the complexity under the hood!

I have one question… are there any examples of using styled-jsx with a custom server? I see you have a request handler in the readme, but I’m not sure how to wire that up to this:

const micro = require('micro')
const match = require('micro-route/match')
const { parse } = require('url')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

const server = micro(async (req, res) => {
  const parsedUrl = parse(req.url, true)
  const { query } = parsedUrl

  if (match(req, '/a')) {
    return app.render(req, res, '/b', query)
  } else if (match(req, '/b')) {
    return app.render(req, res, '/a', query)
  }

  return handle(req, res, parsedUrl)
})

app.prepare().then(() => {
  server.listen(port, err => {
    if (err) throw err
    console.log(`> Ready on http://localhost:${port}`)
  })
})

I’d be happy to contribute back some documentation around this (or a PR example to the next.js repo) if you could help clarify this for me.

Cheers!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
tkellencommented, Sep 3, 2017

Sure can. Ack. I should have started with an isolated test case. Apologies for the wasted time.

For clarity sake, the reason I asked the question to begin with was because of this line in the README:

It’s paramount that you use one of these two functions so that the generated styles can be diffed when the client loads and duplicate styles are avoided.

To my mind that says I need to do something to get SSR rolling for styled-jsx.

I’ll break it down to something small and reproducible (and probably figure out the issue on my own in doing so) later today. Will follow up with my results soon!

0reactions
giuseppegcommented, Dec 17, 2017

Closing this. Happy to reopen in case you need help again 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement server-side rendering in your React app in ...
In this tutorial, we'll use server-side rendering to deliver an HTML response when a user or crawler hits a page URL.
Read more >
Server-Side Rendering in React using Next.js
Server-side rendering with JavaScript libraries like React is where the server returns a ready-to-render HTML page and the JS scripts required ...
Read more >
How to Enable Server-Side Rendering for a React App
First, use npx to start up a new React app using the latest version of Create React App. Let's call the app, react-ssr-example...
Read more >
Basics of React server-side rendering with Express.js
We're going to go through a simple, but limited, implementation of server-side rendering just to get you an idea on how it works....
Read more >
A beginner's guide to React Server-Side Rendering (SSR)
Whenever a user clicks on a link, instead of sending a new request to the server for HTML of that page, we create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found