<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged next</title>
<link>https://coderlegion.com/tag/next</link>
<description>Powered by Question2Answer</description>
<item>
<title>Intercepting Route In Next.js</title>
<link>https://coderlegion.com/27728/intercepting-route-in-next-js</link>
<description>&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Intercepting route is a technique in Next.js that allows you to display a route from another part of your application, within the same current layout, without requiring the user to switch to a different context.&lt;/p&gt;
&lt;p&gt;Intercepting route is always used with  &lt;a rel=&quot;nofollow&quot; href=&quot;https://ali-abd-elbagi-v2.vercel.app/en-US/blog/parallel-route-in-next.js&quot;&gt;parallel route&lt;/a&gt; to build modals.&lt;/p&gt;
&lt;p&gt;For example, when you click on an image on Instagram, what happens is:&lt;/p&gt;
&lt;p&gt;1- A modal appears containing the image and its details, and the feed continues to run in the background.&lt;/p&gt;
&lt;p&gt;2- The link changes from &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.instagram.com&quot;&gt;https://www.instagram.com&lt;/a&gt; to &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.instagram.com/p/DYpin6_DOsV/&quot;&gt;https://www.instagram.com/p/DYpin6_DOsV/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2949956552825418224&quot; alt=&quot;&quot;&gt;&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1417394263151395655&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Intercepting route allows for the construction of this exact model: one link, and two different views depending on the user's approach.&lt;/p&gt;
&lt;h4 id=&quot;behind-the-scenes&quot;&gt;Behind the Scenes&lt;/h4&gt;
&lt;p&gt;What happens exactly is that Next.js intercepts the navigation request for the given page, and instead of displaying the page, it passes it to a specific @slot, which is the  &lt;a rel=&quot;nofollow&quot; href=&quot;https://ali-abd-elbagi-v2.vercel.app/en-US/blog/parallel-route-in-next.js&quot;&gt;Parallel Route&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;folder-structure&quot;&gt;Folder Structure&lt;/h4&gt;
&lt;p&gt;The intercept route file is defined by creating a file that begins with (.), (..), or (..)(..), (...) where:&lt;/p&gt;
&lt;p&gt;(.) is used to match a segment at the same level.&lt;/p&gt;
&lt;p&gt;(..) is used to match a segment one level above.&lt;/p&gt;
&lt;p&gt;(..)(..) is used to match a segment at two levels above.&lt;/p&gt;
&lt;p&gt;(...) is used to match a segment at the root level. The importance of matching is evident when a user opens a new window or shares a link; the modal will not open, but the result will appear on a full standalone page. The intercept segment must match the full standalone page at the same level.&lt;/p&gt;
&lt;p&gt;It should also be noted that the intercept route (...) relies on the route segment for matching, not the file system. The segment is part of the URL, while the &lt;code&gt;@folder&lt;/code&gt; in the  &lt;a rel=&quot;nofollow&quot; href=&quot;https://ali-abd-elbagi-v2.vercel.app/en-US/blog/parallel-route-in-next.js&quot;&gt;Parallel Route&lt;/a&gt;is not considered part of the segment but rather a file system.&lt;/p&gt;
&lt;p&gt;The images below illustrate the file structure :&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15782528588403846737&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=13279591298492409796&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h5 id=&quot;sources&quot;&gt;Sources&lt;/h5&gt;
&lt;p&gt;1- &lt;a rel=&quot;nofollow&quot; href=&quot;https://nextjs.org/docs/app/api-reference/file-conventions/intercepting-routes&quot;&gt;Next.js&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/27728/intercepting-route-in-next-js</guid>
<pubDate>Sat, 19 Sep 2026 10:14:13 +0000</pubDate>
</item>
<item>
<title>How to use parallel routing to build complex routing pattern in Next.js</title>
<link>https://coderlegion.com/26454/how-to-use-parallel-routing-to-build-complex-routing-pattern-in-next-js</link>
<description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Parallel route is a term for a technique in the Next.js framework. It's the process that allows rendering one or more pages simultaneously or based on a specific condition within the same layout.&lt;br&gt;
This concept is used in building dashboards to display multiple pages within a single dashboard, such as displaying the Teams page and the Analytics page, or in building modals that can be shared via URL.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=4587567479774008606&quot; alt=&quot;&quot;&gt;&lt;br&gt;
&lt;em&gt;How parallel routes render multiple sub-pages into a single parent layout. Source: Next doc&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Create Parallel Route&lt;/strong&gt; &lt;br&gt;
parallel route is created by creating a folder called &lt;code&gt;slots&lt;/code&gt;, written like this: &lt;code&gt;@folder&lt;/code&gt;. &lt;em&gt;Note: The &lt;code&gt;@folder&lt;/code&gt; is created at the same level as the &lt;code&gt;layout.tsx&lt;/code&gt; file.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=16378307790993274212&quot; alt=&quot;&quot;&gt;&lt;br&gt;
&lt;/em&gt;file structure defines two explicit slots: @analytics and @team. Source: Next doc*&lt;/p&gt;
&lt;p&gt;After creating @folder file, for example @team, containing a page named page.tsx, the slots for the rootlayout are added as props. It's worth noting that in Next.js, the rootlayout renders children.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// app/layout.tsx
export default function Layout(props: {
  children: React.ReactNode
  team: React.ReactNode
}) {
  return (
    &amp;lt;&amp;gt;
      {props.children}
      {props.team}  
    &amp;lt;/&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;loading.tsx &amp;amp; error.tsx files&lt;/strong&gt;&lt;br&gt;
parallel route allows for the creation of a loading and error file specific to each slot, to display a loading spinner or error page for each route individually.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;default.tsx file&lt;/strong&gt;&lt;br&gt;
The content of the slot that matches the URL, for example: en/team/members, is rendered. This is normal behavior. However, if there is no match between the slot and the URL, a fallback is needed to avoid the common 404 page not found error.&lt;/p&gt;
&lt;p&gt;parallel route relies on the current layout. If the user navigates to a route that doesn't contain a dedicated page within the slot, Next.js searches for the default file to render it as a fallback. If the page refreshes, Next.js searches for the default.tsx file. If it's not there, it returns a 404 error page. It contains:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// default.tsx
export default function Default() {
return null
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Modals&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The importance of the parallel route lies in its ability to create overlay modals, similar to those found on Instagram. For example, when you click on an image, its details are displayed while the feed continues to run in the background. The link changes to something like /photo/flower. If you share the image link, the full image details are displayed, and the feed disappears from the background.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Complex Dashboards&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As mentioned previously, you can display two or more pages on the same dashboard page, each with its own loading.tsx file, and each page's content is separate from the others.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Role-Based &amp;amp; Conditional Access&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can display different pages in the same layout based on the user. For example, if the user is an admin, you display the admin page, and if they are a member, you display the members page.&lt;br&gt;
Within the layout page, the user session is checked, and the appropriate slot is returned.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;export default function Layout(props: {
children: React.ReactNode
teamMember: React.ReactNode
admin: React.ReactNode
}) {
const role = getUserRole(); // Server-side check

return (
&amp;lt;div className=&quot;dashboard-wrapper&quot;&amp;gt;
{props.children}

{role === 'admin' ? props.admin : props.teamMember}

&amp;lt;/div&amp;gt;

)
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;When should I use parallel route?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To determine this, you must answer certain questions such as:&lt;br&gt;
1-Are there specific pages that I need to display on a single page?&lt;/p&gt;
&lt;p&gt;2-Is there a component that needs to be displayed in a window above the main page without needing to close or disappear it?&lt;/p&gt;
&lt;p&gt;3-Are there components in the same view whose display depends on the user's status (admin or regular user)?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://nextjs.org/docs/14/app/building-your-application/routing/parallel-routes&quot;&gt;Next.js&lt;/a&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://medium.com/@sergioarenas025/one-screen-multiple-pages-parallel-routes-in-nextjs-bed6e0176a2c&quot;&gt;Medium&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/26454/how-to-use-parallel-routing-to-build-complex-routing-pattern-in-next-js</guid>
<pubDate>Tue, 08 Sep 2026 05:44:23 +0000</pubDate>
</item>
<item>
<title>Poople Game</title>
<link>https://coderlegion.com/20616/poople-game</link>
<description>&lt;p&gt;Wordle proved that one small puzzle a day, shared by everyone and finished in about a minute, can quietly become a habit. Poople takes that same one-a-day rhythm and points it at a word ladder. You start from a 4-letter word and change one letter at a time until you reach POOP. Every rung along the way has to be a real 4-letter word, and the fewer steps you take, the better your score.&lt;/p&gt;
&lt;p&gt;The whole thing is free, runs in the browser, and needs no account. Your streak and stats live in your own browser, so there is nothing to sign up for and nothing to install. Open the page, solve the puzzle, copy a spoiler-free grid, and get on with your day.&lt;/p&gt;
&lt;h3 id=&quot;the-small-problem-it-solves&quot;&gt;The small problem it solves&lt;/h3&gt;
&lt;p&gt;Most of us already keep a little stack of daily puzzles we open with coffee. The friction shows up fast, though. Some games want an account before you can play. Some bury the puzzle under newsletters and pop-ups. Some take longer than the coffee does. Poople is built to be the opposite of all that. The page is light, the rules fit in one sentence, and a typical day takes under a minute.&lt;/p&gt;
&lt;h3 id=&quot;how-it-works&quot;&gt;How it works&lt;/h3&gt;
&lt;p&gt;A word ladder is an old idea. Lewis Carroll wrote about it in 1877 and called it Doublets. You connect two words by changing one letter at a time while keeping a valid word at every step. In Poople the destination is always POOP, which gives the game its name and a fixed target you can plan around. A new puzzle goes live every day at 08:00 UTC, and every player in the world gets the same starting word that day.&lt;/p&gt;
&lt;p&gt;What makes it satisfying is the planning. You are steering through a graph of words, looking a few moves ahead, and trying to land on the shortest route. It rewards a different muscle than a guessing game does, closer to finding a path through a maze than to filling in blanks.&lt;/p&gt;
&lt;h3 id=&quot;a-solve-looks-like-this&quot;&gt;A solve looks like this&lt;/h3&gt;
&lt;p&gt;Say the day's word is COAT.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;COAT becomes COAL&lt;/li&gt;
&lt;li&gt;COAL becomes COOL&lt;/li&gt;
&lt;li&gt;COOL becomes COOP&lt;/li&gt;
&lt;li&gt;COOP becomes POOP&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That path takes four steps. There may be an even shorter route hiding in the dictionary, and par is that shortest possible path for the day. Matching par is the result to chase, and hunting for it is where the game gets its hooks into you.&lt;/p&gt;
&lt;h3 id=&quot;three-ways-to-play&quot;&gt;Three ways to play&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;The daily puzzle&lt;/strong&gt; is the main event. One shared word ladder for the whole world, refreshed every morning, with a spoiler-free grid you can post when you finish.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Poople Unlimited&lt;/strong&gt; is a free practice mode. Press shuffle for a fresh random starting word whenever you want, with no wait for the next day. It keeps your daily streak untouched, so it is a relaxed place to warm up before the daily puzzle or to keep going after you have solved it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Poople Answers&lt;/strong&gt; is the archive. Once a puzzle closes, its full solution is published the next day. Each entry shows the verified shortest path, progressive hints you can reveal one at a time, short definitions for the bridge words along the way, and an in-page solver that finds the shortest route to POOP from any 4-letter word you type in.&lt;/p&gt;
&lt;h3 id=&quot;details-that-make-the-habit-stick&quot;&gt;Details that make the habit stick&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Spoiler-free sharing.&lt;/strong&gt; Copy a small grid that shows your path without giving away the words you used, in the same spirit as the Wordle share.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Local stats.&lt;/strong&gt; Wins, best streak, and average steps are saved on your device, so your history follows your browser instead of a login.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Keyboard and touch.&lt;/strong&gt; Type on a physical keyboard or tap the on-screen keys, on desktop or mobile.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Par scoring.&lt;/strong&gt; Every puzzle has a known shortest path, so there is always a clear goal beyond simply reaching POOP.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fast and clean.&lt;/strong&gt; The page is light and free of clutter, so it loads quickly and starts the moment it opens.&lt;/p&gt;
&lt;p&gt;On price there is not much to cover. Poople is free, there is no account wall, and there is nothing to download. The daily game stays the daily game, and the practice mode and the archive sit alongside it for anyone who wants more.&lt;/p&gt;
&lt;h3 id=&quot;stack-notes-for-the-engineers-in-the-room&quot;&gt;Stack notes for the engineers in the room&lt;/h3&gt;
&lt;p&gt;Poople runs on Next.js 15 with the App Router, deployed to Cloudflare through OpenNext. Data lives in Cloudflare D1, which is SQLite, with Drizzle ORM on top, and the runtime leans on Cloudflare Workers, Durable Objects, KV, and R2. Copy and translations go through next-intl.&lt;/p&gt;
&lt;p&gt;The part I had the most fun building is the answers pipeline. The day's solution is never written by hand. A breadth-first search over the graph of every valid 4-letter word computes par and a verified shortest path, so each archived answer comes from one deterministic source of truth. A Cloudflare cron trigger publishes the previous day's answer every morning, and at the same time it generates the short bridge-word definitions and a one-line note for that puzzle through an LLM via OpenRouter, then stores them in D1 so the pages stay static and cheap to serve. Each past puzzle gets its own page at /answer/{number}-{word}, statically generated with incremental static regeneration, which turns the archive into a clean programmatic surface that grows by one page a day.&lt;/p&gt;
&lt;p&gt;On the roadmap: more variety in starting words, an optional harder mode, and a small public endpoint for the daily puzzle so people can build their own front-ends and bots around it.&lt;/p&gt;
&lt;h3 id=&quot;try-it&quot;&gt;Try it&lt;/h3&gt;
&lt;p&gt;Play today's puzzle at &lt;a rel=&quot;nofollow&quot; href=&quot;https://pooplegame.com&quot;&gt;https://pooplegame.com&lt;/a&gt;. The practice mode is at &lt;a rel=&quot;nofollow&quot; href=&quot;https://pooplegame.com/unlimited&quot;&gt;https://pooplegame.com/unlimited&lt;/a&gt;, and the answers archive is at &lt;a rel=&quot;nofollow&quot; href=&quot;https://pooplegame.com/answer&quot;&gt;https://pooplegame.com/answer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you give it a try, I would love to hear two things. First, when you get stuck, what is your instinct, do you swap the vowel first or work backward from POOP? Second, for the developers here, would a daily-puzzle API be worth building out? Feedback and bug reports are very welcome.&lt;/p&gt;
</description>
<category>Launches</category>
<guid isPermaLink="true">https://coderlegion.com/20616/poople-game</guid>
<pubDate>Mon, 15 Jun 2026 05:36:21 +0000</pubDate>
</item>
<item>
<title>Streamlining Your Next.js Project with Private GitHub/Gitlab Repositories as NPM Packages</title>
<link>https://coderlegion.com/5276/streamlining-your-next-js-project-with-private-github-gitlab-repositories-npm-packages</link>
<description>&lt;h4 id=&quot;using-private-github-gitlab-repos-in-your-next-js-projects&quot;&gt;Using Private GitHub/Gitlab Repos in Your Next.js Projects&lt;/h4&gt;
&lt;p&gt;Imagine this scenario: you're working on a super cool Next.js project, and you have some shared code that you'd like to use across multiple projects. You don't really want to make it public by publishing it to npm. You also don't want to pay for an npm account to make your repos private. Is there a way to keep it private, secure, yet reusable? You bet!&lt;/p&gt;
&lt;p&gt;In the world of Next.js v13.4 and beyond, using private GitHub or GitLab repositories as npm packages is not only possible, it's also quite straightforward. The steps vary for older versions of Next.js before v13.4 (those using Page Router) and won't be covered in this blog. &lt;/p&gt;
&lt;p&gt;Essentially, we’ll be taking code from a private GitHub or GitLab repository and using it directly in our Next.js project. This method is perfect when you have shared components, utilities, or any other code that you need to reuse across several projects, but don't want to expose to the world (or persevere through the overhead of setting up an npm account).&lt;/p&gt;
&lt;p&gt;Today, I'll walk you through the steps to make this happen. Buckle up, because we're about to make your life a whole lot easier!&lt;/p&gt;
&lt;h5 id=&quot;step-1-create-your-private-github-repo&quot;&gt;Step 1: Create Your Private GitHub Repo&lt;/h5&gt;
&lt;p&gt;This is where your shared code will live. If you already have one, fantastic. If not, go ahead and create a new private repository on GitHub or Gitlab.&lt;/p&gt;
&lt;h5 id=&quot;step-2-generate-a-github-access-token&quot;&gt;Step 2: Generate a GitHub Access Token&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to your GitHub settings (or Gitlab settings for those using Gitlab).&lt;/li&gt;
&lt;li&gt;Create a new personal access token (make sure it only has read access).&lt;/li&gt;
&lt;li&gt;Copy this token and keep it safe (you’ll need it soon).&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 id=&quot;step-3-set-up-your-shared-repo&quot;&gt;Step 3: Set Up Your Shared Repo&lt;/h5&gt;
&lt;p&gt;In your shared repository's &lt;code&gt;package.json&lt;/code&gt;, set the &lt;code&gt;name&lt;/code&gt; field to whatever you'd like to call your package, e.g., &lt;code&gt;&quot;package-name&quot;: &quot;1.0.0&quot;&lt;/code&gt;.&lt;/p&gt;
&lt;h5 id=&quot;step-4-update-your-next-js-project-s-package-json&quot;&gt;Step 4: Update Your Next.js Project’s &lt;code&gt;package.json&lt;/code&gt;&lt;/h5&gt;
&lt;p&gt;In the &lt;code&gt;package.json&lt;/code&gt; of the Next.js project where you want to use your shared code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;dependencies&quot;: {
    &quot;package-name&quot;: &quot;git+https://&amp;lt;github_token&amp;gt;:*Emails are not allowed*/&amp;lt;user&amp;gt;/&amp;lt;repo&amp;gt;.git#branch-name&quot;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace &lt;code&gt;&amp;lt;github_token&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;user&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;repo&amp;gt;&lt;/code&gt;, and &lt;code&gt;branch-name&lt;/code&gt; with the appropriate values from your setup.&lt;/p&gt;
&lt;h5 id=&quot;final-steps-configuration-in-next-js&quot;&gt;Final Steps: Configuration in Next.js&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In your &lt;code&gt;next.config.js&lt;/code&gt;, add the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;module.exports = {
    transpilePackages: [&quot;package-name&quot;],
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This tells Next.js to also compile your typescript code from the shared repo and transform it to javascript - that's basically what transpile means; a combination of the word 'transform' and 'compile'. Without this, you'll get module parsing errors for your typescript (.ts) files.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you're using Tailwind CSS, update your &lt;code&gt;tailwind.config.js&lt;/code&gt; to include your shared package:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;module.exports = {
    content: [
        &quot;./node_modules/&amp;lt;package_name&amp;gt;/src/**/*.{js,ts,jsx,tsx,html,mdx}&quot;,
        &quot;./node_modules/&amp;lt;package_name&amp;gt;/app/**/*.{js,ts,jsx,tsx,html,mdx}&quot;,
    ],
    //… other tailwind config
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace &lt;code&gt;&amp;lt;package_name&amp;gt;&lt;/code&gt; with the name of your shared repo. Also, if you aren't using the &lt;code&gt;src&lt;/code&gt; folder, feel free to adjust the values according to your setup&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now run &lt;code&gt;npm install&lt;/code&gt; and voila! your shared package has now been installed as an NPM dependency and you can use it in your project.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h5 id=&quot;before-we-finish-just-yet&quot;&gt;Before We Finish Just Yet&lt;/h5&gt;
&lt;p&gt;Always remember to update the version number in your package.json with a higher value each time you make a change to your shared repo. After words, run &lt;code&gt;npm update &amp;lt;package_name&amp;gt;&lt;/code&gt; where &lt;code&gt;&amp;lt;package_name&amp;gt;&lt;/code&gt; is the name of your shared package/repo. This will ensure that your changes in the shared package's changes are published to your project.&lt;/p&gt;
&lt;h4 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h4&gt;
&lt;p&gt;Incorporating private GitHub repos as npm packages in your Next.js projects not only keeps your code organized and secure but also significantly boosts your productivity. You no longer need to duplicate code or compromise your privacy by publishing sensitive code to public registries.&lt;/p&gt;
&lt;p&gt;So, what are you waiting for? Dive in and streamline your projects today. And remember, it’s these smart shortcuts that often make a big difference in the efficiency and success of your development efforts.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/5276/streamlining-your-next-js-project-with-private-github-gitlab-repositories-npm-packages</guid>
<pubDate>Wed, 10 Sep 2025 16:53:12 +0000</pubDate>
</item>
<item>
<title>A deep dive into Next.js Rendering for Performance and SEO</title>
<link>https://coderlegion.com/1103/a-deep-dive-into-next-js-rendering-for-performance-and-seo</link>
<description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hey Everyone, Good to see you back! Rendering in Next.js is a crucial aspect that determines how your web pages are generated and served to users. It can be understood as the process of converting code into user interfaces that users can interact with.&lt;/p&gt;
&lt;p&gt;Unlike traditional React applications that rely heavily on Client-Side Rendering (CSR), Next.js pre-renders pages by default, generating HTML in advance, which offers improved performance and SEO benefits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Types of Rendering in Next.js&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next.js offers several rendering strategies, giving developers the flexibility to choose the best approach for each page or application. The rendering methods available in Next.js include &lt;strong&gt;Static Site Generation&lt;/strong&gt; (SSG), &lt;strong&gt;Server-Side Rendering&lt;/strong&gt; (SSR), &lt;strong&gt;Client-Side Rendering&lt;/strong&gt; (CSR), and &lt;strong&gt;Incremental Static Regeneration&lt;/strong&gt; (ISR).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Static Site Generation (SSG)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=14370487558054856523&quot; alt=&quot;ssgimg&quot;&gt;&lt;/p&gt;
&lt;p&gt;This approach creates HTML pages at build time, rather than generating them on demand for each user request. This means that every page of your website is pre-built and stored as static files, and ready to be served instantly when a user accesses the site. The primary benefits of SSG include improved performance, enhanced security, and cost-effectiveness.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why Use Static Site Generation?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Since the HTML files are pre-generated, they load much faster than dynamically generated pages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: Static sites have fewer vulnerabilities because they do not rely on databases or server-side processing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cost-Effectiveness&lt;/strong&gt;: Hosting static files is generally cheaper than hosting dynamic sites.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simplicity&lt;/strong&gt;: Static sites are easier to deploy and maintain.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Implementing SSG&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npx create-next-app ssgShowcase
cd ssgShowcase
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Followed by:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// pages/index.js
export default function Home({ products }) {
   return (
      &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;SSG showcase&amp;lt;/h1&amp;gt;
      &amp;lt;ul&amp;gt;
          {products.map(product =&amp;gt; (
          &amp;lt;li key={product.id}&amp;gt;
          &amp;lt;h2&amp;gt;{product.title}&amp;lt;/h2&amp;gt;
          &amp;lt;p&amp;gt;{product.description}&amp;lt;/p&amp;gt;
          &amp;lt;img src={product.thumbnail} alt={product.title} width=&quot;100&quot; /&amp;gt;
          &amp;lt;/li&amp;gt;
          ))}
      &amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;
     );
    }

    export async function getStaticProps() {
    const res = await fetch('https://dummyjson.com/products?limit=10');
    const data = await res.json();
    const products = data.products;

    return {
    props: {
      products,
    },
  };
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this example, we used the getStaticProps function provided by Next.js to fetch data at build time. When you run npm run dev, Next.js will execute this function, fetch the data from the API, and generate static HTML for each product.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Server Side Rendering (SSR)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1697322640094689026&quot; alt=&quot;ssrimg&quot;&gt;&lt;/p&gt;
&lt;p&gt;Server-Side Rendering (SSR) is a rendering technique where the HTML for a web page is generated on the server in response to each request. This means that every time a user requests a page, the server dynamically generates the HTML and sends it to the browser. Unlike Static Site Generation (SSG), where pages are pre-built at build time, SSR ensures the content is always up-to-date. It uses the &lt;strong&gt;getServerSideProps&lt;/strong&gt; function to fetch data on each request, making it ideal for dynamic content that requires real-time updates or personalized data. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why Use Server-Side Rendering?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Content&lt;/strong&gt;: SSR is ideal for applications that display frequently updated or personalized content.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SEO for Dynamic Pages&lt;/strong&gt;: Like SSG, SSR helps with SEO by providing fully rendered HTML to search engine crawlers. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Fetching at Request Time&lt;/strong&gt;: SSR allows you to fetch data on each request, ensuring that the content is always current.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Implementing SSR&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npx create-next-app ssrShowcase
cd ssrShowcase
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Followed by:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  // pages/index.js
  export default function Home({ meal }) {
  return (
    &amp;lt;div&amp;gt;
         &amp;lt;h1&amp;gt;Recipe of the Day&amp;lt;/h1&amp;gt;
         &amp;lt;h2&amp;gt;{meal.strMeal}&amp;lt;/h2&amp;gt;
         &amp;lt;img src={meal.strMealThumb} alt={meal.strMeal} width=&quot;200&quot; /&amp;gt;
         &amp;lt;p&amp;gt;Category: {meal.strCategory}&amp;lt;/p&amp;gt;
         &amp;lt;p&amp;gt;Instructions: {meal.strInstructions}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    );
  }

  export async function getServerSideProps() {
  const res = await fetch('https://www.themealdb.com/api/json/v1/1/random.php');
  const data = await res.json();
  const meal = data.meals[0];

  console.log(&quot;Meal Data from API:&quot;, meal);
  return {
    props: {
      meal,
    },
   };
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Check the terminal or console where you started the Next.js development server. Each time you refresh the page, you'll see the console.log output, including the data fetched from the API and refreshes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Client Side Rendering (CSR)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17388420265974212457&quot; alt=&quot;csrimg&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this rendering technique, browser renders the web page using JavaScript. It downloads a minimal HTML page along with all the necessary JavaScript. The JavaScript then updates the DOM (Document Object Model) and renders the page. Unlike Server-Side Rendering (SSR) and Static Site Generation (SSG), where the server pre-renders the HTML, CSR generates the content on the client's device.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why Use Client-Side Rendering?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Interactivity&lt;/strong&gt;: CSR is ideal for highly interactive web applications where the user interface needs to respond quickly to user actions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Updates&lt;/strong&gt;: CSR allows you to fetch and render data on-the-fly, enabling dynamic content updates without refreshing the entire page.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reduced Server Load&lt;/strong&gt;: With CSR, the server only sends raw data, reducing the load on the server compared to SSR.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Implementing CSR&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npx create-next-app csrShowcase
cd csrShowcase
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Followed by:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// pages/index.js
import React, { useState, useEffect } from 'react';

export default function Home() {
    const [data, setData] = useState(null);
    const [loading, setLoading] = useState(true);
    const [error, setError] = useState(null);

    useEffect(() =&amp;gt; {
       async function fetchData() {
       try {
         const res = await fetch('https://api.quotable.io/random');
         const json = await res.json();
         setData(json);
       } catch (error) {
          setError(error);
       } finally {
             setLoading(false);
       }
     }
    fetchData();
  }, []);

  if (loading) return &amp;lt;p&amp;gt;Loading...&amp;lt;/p&amp;gt;;
  if (error) return &amp;lt;p&amp;gt;Error: {error.message}&amp;lt;/p&amp;gt;;
  if (!data) return &amp;lt;p&amp;gt;No data&amp;lt;/p&amp;gt;;

  return (
     &amp;lt;div&amp;gt;
       &amp;lt;h1&amp;gt;Quote&amp;lt;/h1&amp;gt;
       &amp;lt;p&amp;gt;{data.content}&amp;lt;/p&amp;gt;
       &amp;lt;p&amp;gt;- {data.author}&amp;lt;/p&amp;gt;
     &amp;lt;/div&amp;gt;
   );
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above example, we use an important hook called &lt;strong&gt;useEffect&lt;/strong&gt; to fetch data from the Quotable API on the client side. The hook runs after the component has rendered. It fetches the data and updates the component's state, triggering a re-render with the new data. So, When you load the page for the first time, you might notice a slight delay because the page isn't fully rendered until all the JavaScript is downloaded, parsed, and executed. Also, you will see &quot;Loading…&quot; text. Once the data is fetched from the API, the page will be rendered with the quote and author. Refreshing the page will fetch new data and update the content dynamically.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Incremental Site Regeneration (ISR)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=14272098050171908937&quot; alt=&quot;isrimg&quot;&gt;&lt;/p&gt;
&lt;p&gt;ISR is a rendering technique in Next.js that allows you to create or update static pages after you've built your application. It enables developers and content editors to use static-generation on a per-page basis, without needing to rebuild the entire application. With ISR, you can retain the benefits of static while scaling to millions of pages. It’s a fairly new way to update static pages and is mainly used for custom built websites.&lt;/p&gt;
&lt;p&gt;ISR in Next.js takes the best of static site generation and server-side rendering. Imagine a request comes in for a page, the server first checks if a static version of the page is available. If it exists, the static page is immediately returned. Meanwhile, the server looks at the age of the page. If it's older than a predefined interval, the server will regenerate the page in the background and replace the old one.&lt;/p&gt;
&lt;p&gt;ISR uses &lt;strong&gt;getStaticProps&lt;/strong&gt; to fetch data. Add the &lt;strong&gt;revalidate&lt;/strong&gt; property to getStaticProps to use ISR. The revalidate property specifies how often a page should be regenerated. Once this period elapses, the next request to the page triggers a regeneration of the page in the background. While the page is being regenerated, the old version of the page continues to be served to users. Upon completion of the regeneration, the old version of the page is replaced with the new one for subsequent requests. This gives you the flexibility to have constantly updating content on your website without compromising on the advantages of static generation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why Use Incremental Static Regeneration?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Faster Builds&lt;/strong&gt;: Reduces build times, especially for large-scale applications.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Content Updates&lt;/strong&gt;: Allows for dynamic content updates without sacrificing performance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Allows you to retain the benefits of static while scaling to millions of pages.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Implementing ISR&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npx create-next-app isrShowcase
cd isrShowcase
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Followed by:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// pages/index.js
export async function getStaticProps() {
     const res = await fetch('https://api.quotable.io/random');
     const data = await res.json();

     return {
       props: {
        quote: data.content,
        author: data.author,
     },
      revalidate: 10, // I have added here for every 10 seconds
     };
  }

  export default function Home({ quote, author }) {
     return (
       &amp;lt;div&amp;gt;
         &amp;lt;h1&amp;gt;Random Quote&amp;lt;/h1&amp;gt;
         &amp;lt;p&amp;gt;{quote}&amp;lt;/p&amp;gt;
         &amp;lt;p&amp;gt;- {author}&amp;lt;/p&amp;gt;
       &amp;lt;/div&amp;gt;
      );
   }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next.js offers a versatile suite of rendering techniques, each designed to optimize different aspects of application development. While SSG should generally be the default choice for its superior performance and SEO with static content, SSR becomes essential for highly dynamic content requiring real-time updates, and CSR remains valuable for interactive application. ISR shines in managing large datasets and content updates without full rebuilds. Understanding the strengths and trade-offs of each method allows you to tailor rendering strategies to meet specific project needs, creating applications that are fast, scalable, and optimized.&lt;/p&gt;
&lt;p&gt;Thank you for making it to the end! I hope you enjoyed the article, please consider sharing it with someone who might benefit from it.&lt;br&gt;
Feel free to reach out to me on &lt;a rel=&quot;nofollow&quot; href=&quot;https://x.com/harshit_rwt&quot;&gt;Twitter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thankyou Once Again!!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wqo9utdt1vt5vth21fh8.png&quot; alt=&quot;Thankyou&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/1103/a-deep-dive-into-next-js-rendering-for-performance-and-seo</guid>
<pubDate>Sat, 08 Feb 2025 14:30:02 +0000</pubDate>
</item>
</channel>
</rss>