Skip to content

TASK4: Next.js. Server Side Rendering#4

Open
Tati-Moon wants to merge 2 commits intomainfrom
feature/nextjs-ssr-pages-api
Open

TASK4: Next.js. Server Side Rendering#4
Tati-Moon wants to merge 2 commits intomainfrom
feature/nextjs-ssr-pages-api

Conversation

@Tati-Moon
Copy link
Owner

@Tati-Moon Tati-Moon commented Mar 9, 2025

Hello everyone, and thank you for reviewing the assignment.

I have created two branches: "nextjs-ssr-pages-api" and "nextjs-ssr-app-router-api". However, I have some questions regarding the use of LocalStorage—no one has answered how to handle it in Next.js, so I have temporarily left it as is.

Additionally, I encountered issues with testing. In the first branch ("nextjs-ssr-pages-api"), I was unable to fix the errors, and in the second branch, I struggled to achieve proper test coverage. Perhaps it would have been better to start a new project from scratch and then build the pages, as debugging errors during migration using guides has proven to be quite challenging.

I would appreciate any comments, and if you have time, I’d be grateful for any help with the issues I’m facing.

===============

  1. Task: link
  2. Screenshot:
  3. Deploy: link
  4. Done 09.03.2025 / deadline10.03.2025
  5. Score: 80 / 150
  • Next.js Pages API is used in "nextjs-ssr-pages-api" branch. Pages render on the server - 50
  • Next.js App Router API is used in "nextjs-ssr-app-router-api" branch. Pages render on the server with RSC - 50
  • [Optional] React Router 7 is used in "react-router-ssr" branch. Pages render on the server - 50

Summary by Sourcery

Implements server-side rendering using Next.js Pages API, Next.js App Router API, and React Router 7.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 9, 2025

Reviewer's Guide by Sourcery

This pull request migrates the application from Vite to Next.js, focusing on enabling Server-Side Rendering (SSR). The implementation involves creating Next.js configuration files, updating the TypeScript configuration, creating a root layout, setting up an entry point page, updating static image imports, migrating environment variables, and updating scripts in package.json. The pull request also includes steps to clean up Vite-related files and install SASS.

Sequence diagram for rendering a page in Next.js

sequenceDiagram
    participant Browser
    participant Next.jsServer
    participant PageComponent
    participant ClientComponent

    Browser->>Next.jsServer: Request Page
    Next.jsServer->>PageComponent: Render Page (Server Component)
    PageComponent->>ClientComponent: Render Client Component
    ClientComponent-->>PageComponent: Return rendered Client Component
    PageComponent-->>Next.jsServer: Return rendered Page
    Next.jsServer-->>Browser: Send HTML
    Browser->>ClientComponent: Hydrate Client Component
Loading

File-Level Changes

Change Details Files
Configured Next.js for Server-Side Rendering.
  • Installed Next.js as a dependency.
  • Created a next.config.mjs file to configure Next.js.
  • Configured the output to be a Single-Page Application (SPA).
  • Changed the build output directory to ./dist/.
README.md
Updated TypeScript configuration to be compatible with Next.js.
  • Removed the project reference to tsconfig.node.json.
  • Added ./dist/types/**/*.ts and ./next-env.d.ts to the include array.
  • Added ./node_modules to the exclude array.
  • Added { "name": "next" } to the plugins array.
  • Set esModuleInterop to true.
  • Set jsx to preserve.
  • Set allowJs to true.
  • Set forceConsistentCasingInFileNames to true.
  • Set incremental to true.
README.md
Created a root layout for Next.js.
  • Created src/app/layout.tsx as the root layout file.
  • Moved metadata files (e.g., favicon, robots.txt) into the app directory.
  • Used the Metadata API for managing head content.
README.md
Configured the entrypoint page for Next.js.
  • Created a directory app/[[...slug]]/ and a page.tsx file inside it.
  • Created a client.tsx file for running the Vite application in Next.js as a client-side app.
  • Updated page.tsx to render the client-only component.
README.md
Updated static image imports to be compatible with Next.js.
  • Changed image imports to reference the public directory.
  • Updated the src attribute of the img tag to use image.src.
README.md
Migrated environment variables to Next.js format.
  • Changed all VITE_ variables to NEXT_PUBLIC_.
  • Replaced import.meta.env.MODE with process.env.NODE_ENV.
  • Replaced import.meta.env.PROD with process.env.NODE_ENV === 'production'.
  • Replaced import.meta.env.SSR with typeof window !== 'undefined'.
README.md
Updated scripts in package.json to use Next.js commands.
  • Updated the dev script to use next dev.
  • Updated the build script to use next build.
  • Updated the start script to use next start.
README.md
Cleaned up Vite-related files.
  • Deleted main.tsx.
  • Deleted index.html.
  • Deleted vite-env.d.ts.
  • Deleted vite.config.ts.
  • Uninstalled Vite dependencies.
README.md
Installed SASS.
  • Installed the sass package.
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Tati-Moon - I've reviewed your changes - here's some feedback:

Overall Comments:

  • It would be helpful to include a brief description of the specific changes made in each branch.
  • Consider adding a section on error handling or unexpected scenarios during the migration.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


If you're using TypeScript, update your `tsconfig.json` file with the following changes to make it compatible with Next.js. If not, you can skip this step.

- Remove the project reference to `tsconfig.node.json`
Copy link

Choose a reason for hiding this comment

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

suggestion: Clarify removal of project reference

Change "Remove the project reference to tsconfig.node.json" to "Remove the project reference from tsconfig.json* to* tsconfig.node.json`"

Suggested change
- Remove the project reference to `tsconfig.node.json`
- Remove the project reference from `tsconfig.json` to `tsconfig.node.json`

}
```

2. Move relevant metadata files (e.g., favicon, robots.txt) into the `app` directory and remove `<link>` tags.
Copy link

Choose a reason for hiding this comment

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

suggestion: Specify origin of metadata files

Clarify where the metadata files should be moved from. For example, "Move relevant metadata files (e.g., favicon, robots.txt) from the project root into the app directory."

Suggested change
2. Move relevant metadata files (e.g., favicon, robots.txt) into the `app` directory and remove `<link>` tags.
2. Move relevant metadata files (e.g., favicon, robots.txt) from the project root into the `app` directory and remove `<link>` tags.

2. **After**:

```tsx
import image from '../public/img.png';
Copy link

Choose a reason for hiding this comment

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

suggestion: Clarify public directory usage for images

Explain the difference in paths between the "Before" and "After" examples, and clarify that images should be placed in the public directory.

Suggested change
import image from '../public/img.png';
import image from '../public/img.png';
Note: The updated path now points to the public directory. In the "Before" example, the image was imported from a local directory (./img.png). In Next.js, static images should be placed in the public directory, hence the updated path (../public/img.png) to ensure the assets are served correctly.

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.

1 participant