swapnilsparsh / DevEmpire

All in one place where you can find all the resources and details of ambassador/ fellowship, open-source events, web dev sites, games and etc. that are available across different sites.
https://devempire.netlify.app
127 stars 130 forks source link

[FEATURE] Migration from Pages Router to App Router in Next.js #330

Closed s2sharpit closed 1 year ago

s2sharpit commented 1 year ago

Detailed description

I would like to propose a migration from the existing Pages Router to the new App Router in Next.js. This transition would bring numerous benefits and enhance the overall development experience.

Benefits

Allow me to outline the advantages of adopting the App Router over the Pages Router:

  1. Improved Performance: The App Router introduces optimized client-side routing, resulting in faster navigation between pages. By utilizing dynamic imports, it enables code splitting, leading to smaller initial page loads and improved performance for users.

  2. Enhanced Developer Experience: The App Router simplifies the management of complex routing scenarios. It offers a more intuitive and declarative API, allowing developers to define their routes in a centralized configuration file. This approach improves code maintainability and reduces duplication, leading to a cleaner and more scalable codebase.

  3. Enhanced Code Splitting: The App Router allows for granular control over code splitting, enabling us to dynamically load only the necessary components for each page. As a result, the initial page load is significantly faster, and subsequent navigations are more efficient.

  4. Advanced Route Handling: The App Router introduces additional features such as nested routes, parameter-based routing, and dynamic route segments. These capabilities enable more flexible and dynamic page structures, making it easier to handle various URL patterns and create dynamic routes that adapt to different contexts.

  5. SEO-Friendly: The App Router supports server-side rendering (SSR) and static site generation (SSG), making it SEO-friendly out of the box. It ensures that search engines can crawl and index your application's pages effectively, improving discoverability and organic traffic.

  6. Layout Flexibility: Unlike the Pages Router, which enforces a strict file-based layout structure, the App Router allows us to have more flexibility in designing layouts. We can easily create shared layouts that wrap multiple pages without duplicating code, promoting better code organization.

Possible implementation

Migration Plan

To ensure a smooth transition from the Pages Router to the App Router, I suggest the following migration plan:

  1. Conduct a thorough code analysis and identify all the relevant routes currently implemented with the Pages Router.

  2. Create a test branch to implement the App Router in the existing codebase, while keeping the Pages Router intact to avoid disrupting the application's functionality during the migration process.

  3. Migrate one route at a time, testing each page thoroughly to ensure functionality remains consistent.

  4. Update any custom code associated with navigation, such as Link components, to work with the App Router.

  5. Conduct rigorous testing, including performance tests, to benchmark the improvements achieved through the migration.

  6. Ensure the codebase adheres to the best practices and conventions recommended by Next.js for App Router implementation.

  7. Update the documentation and provide clear instructions for developers on how to work with the new App Router.

Conclusion

I believe that migrating to the App Router is a valuable step for our project, bringing numerous benefits to both developers and end-users. The improved performance, enhanced developer experience, advanced route handling, SEO-friendliness, and layout flexibility make it a compelling choice. With the suggested migration plan, we can ensure a smooth and successful transition. I would be more than happy to assist with the migration process and provide any necessary support.

Thank you for considering this proposal. I look forward to discussing and implementing this change.

github-actions[bot] commented 1 year ago

Hey @s2sharpit,

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.

Please make sure you have given us as much context as possible.

swapnilsparsh commented 1 year ago

@s2sharpit Go ahead 🙌🏻

github-actions[bot] commented 1 year ago

Hey @s2sharpit, thank you for raising an issue. I have assigned the issue to you. You can now start working on it. If you encounter any problems, feel free to connect with us.

s2sharpit commented 1 year ago

Thank you for assigning me to this issue. I appreciate the opportunity to work on implementing the migration from the existing Pages Router to the new App Router in Next.js.

To ensure a focused and organized approach, I kindly request that you create a dedicated branch specifically for this migration, such as "app-router-migration." This will allow us to work on the migration without disrupting the main development branch and maintain the application's functionality throughout the process.

Once the branch is created, I will proceed with the following steps:

  1. Implement the App Router: I will begin implementing the App Router in the "app-router-migration" branch while keeping the existing Pages Router intact.

  2. Migrate one route at a time: I will migrate each route individually, ensuring that each page functions properly with the App Router.

  3. Thorough testing: I will conduct comprehensive testing on each page after migration to ensure consistent functionality and identify any issues.

  4. Update navigation code: I will update any custom code related to navigation, such as Link components, to work seamlessly with the App Router.

  5. Adhere to best practices: I will ensure that the codebase adheres to the best practices and conventions recommended by Next.js for implementing the App Router.

If you have any questions, suggestions, or specific guidelines you would like me to follow during the migration process, please let me know. I value your input and want to ensure that the migration aligns with your expectations.

Thank you for your trust in me to handle this task. I'm excited to work on this enhancement and I'm available to provide any support or assistance throughout the migration process.

swapnilsparsh commented 1 year ago

@s2sharpit very informative guidelines that you shared so I suggest you make a new branch and start the work there. Once done then create a PR after that the changes which are required to be added will be handled by me so you independently work on a new branch. Good Luck 👍🏻

s2sharpit commented 1 year ago

@s2sharpit very informative guidelines that you shared so I suggest you make a new branch and start the work there. Once done then create a PR after that the changes which are required to be added will be handled by me so you independently work on a new branch. Good Luck 👍🏻

Thanks for your reply @swapnilsparsh. I'm glad you found my guidelines informative. I was initially planning to raise about 6 to 8 pull requests (PRs) to complete the migration task, ensuring a systematic approach. However, if you prefer, I can work on a single PR as you suggested. Let me know your thoughts on the multiple PR approach. If you still want to proceed with a single PR, I'll adapt my strategy accordingly. Looking forward to your response.

s2sharpit commented 1 year ago

I have an alternative approach for the migration process that doesn't require creating another branch. We can convert one page at a time to the App Router while keeping the rest in the Page Router, ensuring it will not affect the deployment or functionality of the project. Once each page is successfully migrated, we can merge the changes directly into the main branch. This step-by-step approach can simplify the migration process. What do you think of this idea? Your feedback is appreciated.

swapnilsparsh commented 1 year ago

I have an alternative approach for the migration process that doesn't require creating another branch. We can convert one page at a time to the App Router while keeping the rest in the Page Router, ensuring it will not affect the deployment or functionality of the project. Once each page is successfully migrated, we can merge the changes directly into the main branch. This step-by-step approach can simplify the migration process. What do you think of this idea? Your feedback is appreciated.

This approach looks more better to me. Go ahead 🙌🏻

s2sharpit commented 1 year ago

Hello @swapnilsparsh,

I hope this message finds you well. While working on the current issue, I've discovered that our current approach to implementing themes in Next.js may not be the best practice. After conducting some research, I came across the next-themes package, which appears to provide a more efficient solution.

I wanted to discuss the possibility of converting our theming implementation to use the next-themes package. This change could offer several benefits, including improved performance and enhanced flexibility. I believe it would be a worthwhile endeavor to explore this alternative approach.

I would greatly appreciate your guidance and approval to proceed with converting our theming implementation to utilize the next-themes package. Please let me know your thoughts on this proposal and whether it aligns with our project's goals and requirements.

Thank you for your time and consideration.

swapnilsparsh commented 1 year ago

@s2sharpit I don't think the next theme is the best option to consider. We should follow the new documentation of next js 13 which is there to make the best use from it.

s2sharpit commented 1 year ago

@s2sharpit I don't think the next theme is the best option to consider. We should follow the new documentation of next js 13 which is there to make the best use from it.

Thank you for your message. I understand your point about the new documentation for Next.js 13, but I couldn't find any information about theming in it. If you have come across any details regarding theming in Next.js 13, I would appreciate it if you could share them with me. I believe it's important for us to explore all the available options before making a decision.

swapnilsparsh commented 1 year ago

@s2sharpit I was finding the app page appraoch best, but you can document all the possible ways with pros and cons from wherer we can go ahead to make the final decisionl.

s2sharpit commented 1 year ago

Subject: Next.js 13 Migration: Evaluating Migration Approaches

Hello @swapnilsparsh ,

Thank you for your response. I appreciate your input regarding the migration of our Next.js project to Next.js 13. After considering your perspective, as well as exploring the available options, I believe we should carefully evaluate the pros and cons of each approach before making a final decision. Let's discuss the two possible migration strategies in more detail:

1. Gradual Migration: Migrate Pages Individually

Pros:

Cons:

2. Recommended Approach: Incremental Migration

Pros:

Cons:

Additionally, it's worth noting that the best approach to using themes in Next.js is to leverage a widely used library called next-themes. This library has gained popularity among Next.js projects and is even used by the maintainer of the Next.js repository, Lee Robinson, in his own projects. Incorporating next-themes into our migration process can provide a reliable and community-supported solution for implementing themes in our Next.js application.

Considering the complexity involved in migrating shared components, I am inclined to favor the incremental migration approach. By following the recommended guidelines and utilizing next-themes for theming, we can ensure a smoother transition to Next.js 13 while maintaining the integrity of our shared components.

I would love to hear your thoughts on these approaches and whether you have any additional insights or concerns. It is important for us to thoroughly evaluate each option before finalizing our decision. Please feel free to share your perspective, and let's collaborate to find the best solution for our project.

Thank you once again for your time and contribution.

Best regards, Tushar

Additional Resources:

swapnilsparsh commented 1 year ago

@s2sharpit GIve me some time to make decision, will let you know soon.

s2sharpit commented 1 year ago

@s2sharpit GIve me some time to make decision, will let you know soon.

Ya Sure.

swapnilsparsh commented 1 year ago

@s2sharpit Thank you providing the insight but right not I feel the page router is better. I will be changing soon to app router but not right now. Good Luck 👍

github-actions[bot] commented 1 year ago

Hey @s2sharpit, This issue is closed.