Skip to content

SSR Exercises

Alright, let's get some practice!

Check out the following Git repository, which includes three SSR-related exercises:

Clock

Earlier in this course, we built a clock! In this exercise, we'll adapt that code so that it works in a server-side rendering context.

Acceptance Criteria:

  • There should be no errors.

Getting started:

You'll find the files for this exercise in /src/app/exercises/01-clock.

Once you've started a dev server with npm run dev, you can visit localhost:3000/exercises/01-clock to view the app in-browser. If you're using CodeSandbox, you can append /exercises/01-clock to the URL shown in the dev:3000 pane.

Solution:

Neighborhood Shop

This next exercise features a checkout flow for an e-commerce shop:

Your mission is to persist the user's cart in Local Storage, so that their cart isn't lost when refreshing the page. Your approach should be SSR-compatible, using the techniques we learned in the previous lesson.

You'll find the files for this exercise in /src/app/exercises/02-checkout.

Acceptance Criteria:

  • A user's cart should not be lost when refreshing the page.
  • The user should never be lied to about their cart. If they have saved items, they shouldn't see "Your cart is empty", not even for a second.
    • Instead, you can show a loading indicator. You'll find a suitable component in /src/components/Spinner.
  • There should be no hydration-related errors, and no errors inside the server terminal.
  • You'll need to tweak code in multiple files. Don't be afraid to restructure the provided code!

Solution:

Artist Interview

Finally, we'll tackle a responsive interview layout.

This page has an “About the Artist” sidebar. This sidebar is intended to be hidden on smaller devices. The current implementation, however, is not SSR friendly. Your job is to fix it.

You'll find the files for this exercise in /src/app/exercises/03-interview.

Acceptance Criteria:

  • The initial code has a hydration mismatch on desktop/tablet window sizes (>500px). Your main task is to remove the mismatch.
  • No other errors should be thrown, on the server or the client.
  • The sidebar should not be visible when the window is less than 500px wide.

Solution: