Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

major: full dynamic pages and plain next.js #5426

Merged
merged 6 commits into from
Jun 27, 2023
Merged

major: full dynamic pages and plain next.js #5426

merged 6 commits into from
Jun 27, 2023

Conversation

ovflowd
Copy link
Member

@ovflowd ovflowd commented Jun 12, 2023

Description

This PR implements the Discussion started here on leaving Nextra in favour of a vanilla Next.js experience.

Truth be told, as mentioned in the discussion, we finally matured so that we don't need Nextra anymore.

This PR implements an engine that allows Incremental Builds (SSR) and full Static Builds of non-localised pages with localised context(s).

Leveraging Next.js Dynamic Routes feature (Static Paths + On-demand Static Page Generation).

This also uses MDX Remote for the compilation of MDXm for Next.js on build-time and on-demand.

How it works

  • We first detect if the built environment is "static export" or regular builds (Standalone, Vercel)
  • We determine if the pages should be built statically or not based on that (since with standalone/vercel we can support complete ISR for all existing pages
    • If on an ISR environment, we also support generating blog pages on-demand
    • Otherwise, we only generate all pages, excluding blog posts, as the static builds would be gigantic and too long.
    • On the ISR environment, we skip building the non-localized pages at build time to speed up the build.
  • Then, when the page is requested, we load their Markdown data and then parse the Markdown source with MDXRemote
    • We add extra context (such as blog data) if needed
  • The page is rendered by invoking the NextraTheme with necessary props

Related Issues

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npx turbo lint to ensure the code follows the style guide. And run npx turbo lint:fix to fix the style errors if necessary.
  • I have run npx turbo format to ensure the code follows the style guide.
  • I have run npx turbo test to check if all tests are passing, and/or npx turbo test:snapshot to update snapshots if I created and/or updated React Components.
  • I've covered new added functionality with unit tests if necessary.

@ovflowd ovflowd added website redesign Issue/PR part of the Node.js Website Redesign infrastructure Issues/PRs related to the Repository Infra labels Jun 12, 2023
@ovflowd ovflowd requested a review from a team as a code owner June 12, 2023 22:27
@vercel
Copy link

vercel bot commented Jun 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nodejs-org ❌ Failed (Inspect) Mar 19, 2024 2:34pm
nodejs-org-stories ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2024 2:34pm

@vercel
Copy link

vercel bot commented Jun 12, 2023

@ovflowd is attempting to deploy a commit to the OpenJS Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 12, 2023 22:28 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 12, 2023 22:35 Inactive
@AugustinMauroy
Copy link
Member

Hey! That's great.
Question do we keep the contents in the page folder? Wouldn't it be smarter to make a content folder? So in the pages folder we'd only have .tsx and the md|mdx would be in the content directory. The pages folder would be the skeleton with the layouts.

@ovflowd
Copy link
Member Author

ovflowd commented Jun 13, 2023

Question do we keep the contents in the page folder? Wouldn't it be smarter to make a content folder? So in the pages folder we'd only have .tsx and the md|mdx would be in the content directory. The pages folder would be the skeleton with the layouts.

No, it is not smarter to have a content folder. As I mentioned before and it was documented before, for the time being, we want to keep the structure of the content/pages as much as simple and easy to understand for existing long-term contributors and newcomers.

A specific content folder brings no benefits and only adds complexity. A content folder also doesn't solve the original issue, so not even sure why you're mentioning it here.

The pages folder would be the skeleton with the layouts.

I know how this works, we did it on Gatsby a long time ago. But Next.js works differently, and even tho we could load the content dynamically only from a content folder, it is kinda anti-intuitive.

The current approach exists to support non-localized pages to have their source content to be shown and still be localised.

This works because:

  • We know all the paths at build time by analysing the pages/en/** folder, with the content folder we have no idea what is the SLUG that each page should have. (Only if we adopted the same folder structure)
  • We don't want to have dynamic page creation for static pages. This is an anti-pattern. The biggest purpose for dynamic pages is at the title itself "dynamic pages", not "static pages". The non-localized pages fit this criterion because they are actually dynamic because they don't exist and might change at each build (as more content gets translated).
  • We want to avoid having a separation of content <> page skeleton. A page should have its content and components together. This would avoid the mess we had on Gatsby.

Also, gentle reminder that you already asked me this a few times, and I find it kinda annoying that you keep insisting on it (if that was not your intention, then I'm sorry 😅)

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

LGTM !
Thanks Claudio for your answer.

@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 08:24 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 08:32 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 09:33 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 13, 2023 09:49 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 11:35 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 13, 2023 12:02 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 13:09 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 16:57 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 22:50 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 23:03 Inactive
@ovflowd
Copy link
Member Author

ovflowd commented Jun 13, 2023

Updates on the PR

  • I've updated this PR replacing some of the existing logic for the next-data middlewares. Also note that once chore: consolidate Node releases data #5365 gets merged next-data will pretty much only be generating runtime blog data for the blog pages and the RSS feeds rebuild.
  • The existing next-data folder was moved to the root next-data and the files were updated with better docs, removal of unused code, improvement of existing code
  • The PR now introduces dynamic routes for blog/year-XXXX routes, instead of generating Markdown on the filesystem
  • Some other minor improvements were done to performance
  • Files were relinted (hence some changes purely on linting) and reformatted

@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 13, 2023 23:30 Inactive
@ovflowd
Copy link
Member Author

ovflowd commented Jun 14, 2023

cc @nodejs/website having reviews would be nice here :)

Copy link
Collaborator

@bmuenzenmeyer bmuenzenmeyer left a comment

Choose a reason for hiding this comment

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

An initial manual pass - hoping to run the code this weekend on my Windows machine

next-data/generateWebsiteFeeds.mjs Outdated Show resolved Hide resolved
next-data/getBlogData.mjs Outdated Show resolved Hide resolved
next-data/helpers.mjs Outdated Show resolved Hide resolved
next-data/helpers.mjs Outdated Show resolved Hide resolved
next-data/helpers.mjs Outdated Show resolved Hide resolved
next.dynamic.mjs Outdated Show resolved Hide resolved
next.dynamic.mjs Outdated Show resolved Hide resolved
pages/[locale]/[...pathname].tsx Outdated Show resolved Hide resolved
pages/[locale]/blog/[year].tsx Outdated Show resolved Hide resolved
theme.dynamic.tsx Outdated Show resolved Hide resolved
@ovflowd
Copy link
Member Author

ovflowd commented Jun 17, 2023

Going to rebase and update based on code-review soon.

@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 18, 2023 09:17 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 18, 2023 09:23 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 18, 2023 09:28 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 18, 2023 09:41 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 26, 2023 17:11 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 26, 2023 17:45 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 26, 2023 17:45 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 26, 2023 19:22 Inactive
@ovflowd ovflowd changed the title feat: dynamic incremental generation for localized pages major: full dynamic pages and plain next.js Jun 26, 2023
@ovflowd
Copy link
Member Author

ovflowd commented Jun 26, 2023

Hey, @nodejs/website I've updated this PR and now it contains the full solution of:

  • Using plain Next.js without Nextra
  • Dynamic Pages
  • Refactoring of next-data

Everything is working as expected now!

@vercel vercel bot temporarily deployed to Preview – nodejs-org June 26, 2023 19:30 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 26, 2023 19:44 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 26, 2023 19:46 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 26, 2023 20:10 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 26, 2023 21:01 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 26, 2023 21:01 Inactive
Copy link
Member

@araujogui araujogui left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@bmuenzenmeyer bmuenzenmeyer left a comment

Choose a reason for hiding this comment

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

I want to run the code locally again but thought I'd submit this initial review

CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
components/Home/HomeDownloadButton.tsx Show resolved Hide resolved
components/Home/HomeDownloadButton.tsx Show resolved Hide resolved
next.constants.mjs Outdated Show resolved Hide resolved
next.dynamic.mjs Outdated Show resolved Hide resolved
next.dynamic.mjs Outdated Show resolved Hide resolved
next.locales.mjs Outdated Show resolved Hide resolved
pages/[...path].tsx Outdated Show resolved Hide resolved
Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com>
Signed-off-by: Claudio Wunder <cwunder@gnome.org>
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 27, 2023 09:00 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories June 27, 2023 09:10 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org June 27, 2023 09:15 Inactive
@aymen94 aymen94 merged commit 2dc6293 into nodejs:main Jun 27, 2023
@ovflowd
Copy link
Member Author

ovflowd commented Jun 27, 2023

@aymen94 I think it was premature to get such a massive PR merged without more reviews from other folks.

But I guess it's fine 😅

@ovflowd ovflowd deleted the feat/dynamic-rendering branch June 27, 2023 14:35
@aymen94
Copy link
Member

aymen94 commented Jun 27, 2023

@aymen94 I think it was premature to get such a massive PR merged without more reviews from other folks.

But I guess it's fine 😅

@ovflowd I understand your point regarding the number of reviews for merging a completely new development. While four reviews may seem like enough, I appreciate your suggestion to pay attention. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Issues/PRs related to the Repository Infra website redesign Issue/PR part of the Node.js Website Redesign
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Redirection of Content through SSR/Middlewares
5 participants