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

♻️ Full migration from app router PLUS next15/react19 #450

Merged
merged 15 commits into from
Dec 19, 2024

Conversation

KemingHe
Copy link
Collaborator

@KemingHe KemingHe commented Dec 16, 2024

Completes #375

Part 1/2 Page Router -> App Router

  • All existing Playwright behavior testing passing. 5b60e5b
  • Added new Playwright screenshot tests to all 4 image endpoints. 74809d6
  • Updated unit tests to reflect the new architectural changes.

Part 2/2 -> Next15/React19 via Official Codemod

  • Breezed through Codemod, fully upgraded deps and types, no major/minor code changes.
  • Updated typing based on latest docs.
  • Added component update timeout to Playwright user story test to prevent eaten input. aba4b28
  • Updated variable names based on latest owner feedback.

Thank you @wei for your tremendous support; I look forward to replying to your review.

Edit: additional context

Screenshot all 4 GET image api endpoints with complex config per viewport type (Chrome and Mobile Chrome) in preparation for migration. Also updated TailwindCSS config from .js to .ts.
Followed nextjs official docs and best practices, backed by Playwright behavior regression test passing. Upated unit tests to reflect the new framework.
Copy link

changeset-bot bot commented Dec 16, 2024

🦋 Changeset detected

Latest commit: b809885

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
socialify Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for github-socialify ready!

Name Link
🔨 Latest commit b809885
🔍 Latest deploy log https://app.netlify.com/sites/github-socialify/deploys/67638ce148710e000893c702
😎 Deploy Preview https://deploy-preview-450--github-socialify.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Owner

@wei wei left a comment

Choose a reason for hiding this comment

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

This is wonderful 💯! I see so many great improvements.

I left a few questions above please review and lmk your thoughts.

I'll conduct a more thorough review when I'm on my computer tomorrow. 🙌

src/hooks/useRouteResources.ts Outdated Show resolved Hide resolved
src/components/configuration/config.tsx Show resolved Hide resolved
app/layout.tsx Outdated Show resolved Hide resolved
Upgraded using the official NextJS codemod. No file modded by the codemod. Updated types and deps. Fully compatible with exising behavior tests, all passed.
@KemingHe KemingHe changed the title ♻️ Full front+backend migration from page router to app router ♻️ Full migration from app router PLUS next15/react19 Dec 16, 2024
@KemingHe KemingHe marked this pull request as draft December 16, 2024 02:17
@KemingHe KemingHe marked this pull request as ready for review December 16, 2024 02:31
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
@wei wei force-pushed the upgrade-pagarouter2approuter-keminghe branch from b0e8cca to d00a7b9 Compare December 17, 2024 06:49
Regressively tested all the requested changes, and determined safe to keep them. Added server-only prod dep to explicitly limit code involving GITHUB_TOKEN to only run server-side.
@KemingHe
Copy link
Collaborator Author

server-only is a react (not next) marker that enforces usage of the module that imports it to run on server-side. It's widely used to explicitly protect code involving server-side secrets.

I'll let you ultimately decide whether to keep it. It's extremely light-weight w/ no versioning/upgrade needed.

@wei
Copy link
Owner

wei commented Dec 17, 2024

Copy link
Owner

@wei wei left a comment

Choose a reason for hiding this comment

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

@KemingHe
Copy link
Collaborator Author

Hi @wei , I used https://realfavicongenerator.net/ to double-confirm my favicon and manifest updates are good. I did not re-generate/format any of the files, only copy/rename.

P.S. It's a known issue that their site's favicon.ico check is bugged recently, everything else works fine, so no worries.

@KemingHe
Copy link
Collaborator Author

I also found this unexpected behavior where the import breaks for the wasm module as soon as I touched the public dir. The fix is to revert (only) them to relative imports.

I suspect this is related to how next caches/imports? public dir and how the behavior changed once favicon.ico and manifest.json got moved out.

@wei
Copy link
Owner

wei commented Dec 18, 2024

@KemingHe That all sounds and looks great! I was previewing the feature branch and noticed the selected font is not loaded for the preview. Everything else is working well. Could you help confirm the font is loaded correctly?

image

@KemingHe
Copy link
Collaborator Author

Hi @wei , assuming you are referring to the latest https://deploy-preview-450--github-socialify.netlify.app/ preview, here's what I found:

  • All image urls are working (with custom fonts).
  • Only the Inter/Non-inter font change is working on preview config page (page refresh doesn't fix it).

I have a few ideas on the root cause, but before we get into that, what if you try to create a branch off the current working master and deploy a preview without any changes to see if the issues are also present and consistent?

If so I argue that we are actually good to merge to master. Otherwise we can keep investigating. What do you think?

@wei
Copy link
Owner

wei commented Dec 19, 2024

@KemingHe good point!

I just checked the master branch deployment: https://master--github-socialify.netlify.app
Permalink: https://67611dae31fa580008b7c232--github-socialify.netlify.app

I can confirm the other fonts are working correctly on the preview page there but not in this pull request preview url.

@KemingHe
Copy link
Collaborator Author

KemingHe commented Dec 19, 2024

Wait, @wei , I meant the difference between preview and production deployments might be the most immediate cause (and of course, then there's the root cause). You said you checked the master production deployment, correct? What if you create a branch off from current master and trigger a preview deployment?

Edit: typo


On top of such, I also noticed that a serif default font (not in font list) is applied to the not-working fonts config cases. Are you familiar with this (only seen on preview config page, all image APIs are unaffected and fine)?

Screenshot 2024-12-18 at 8 18 32 PM

This is not the inter font we defined in the Rootlayout as Inter is sans-sarif.

@wei
Copy link
Owner

wei commented Dec 19, 2024

I believe the permalink act the same as the pull request preview deployments.


Image APIs add fonts within the svg so it's slightly different:

fonts: await getFonts(config.font),

Whereas the preview page loads font here:

<Head>
<link
href={`https://fonts.googleapis.com/css2?family=Jost:wght@400&display=swap`}
rel="stylesheet"
key="preview-card-fonts-1"
/>
<link
href={`https://fonts.googleapis.com/css2?family=${config.font}:wght@200;400;500&display=swap`}
rel="stylesheet"
key="preview-card-fonts-2"
/>
</Head>

I noticed in master, these two font stylesheet links are added to head, but not in the pull request preview domain:
image

I see no changes around these lines in this PR so it might be related to how <Head> and link tags are handled.

RE: font fallback. Fallback is not used as defined in root layout as the font family was overwritten without a fallback:
image

@wei
Copy link
Owner

wei commented Dec 19, 2024

It is bad practice to have two <head>s in an html, the nextjs <Head> is a helper component acting a portal to move whatever is in there to the actual html's <head>.

@KemingHe
Copy link
Collaborator Author

I propose we (I) modify the current Playwright simpleUserStory.spect.ts to cover this case. This will require a snapshot update. What do you think?

@wei
Copy link
Owner

wei commented Dec 19, 2024

Confirmed next/head does not work with app router per vercel/next.js#53529 (comment)

I'm working on an alternative.

@wei
Copy link
Owner

wei commented Dec 19, 2024

I propose we (I) modify the current Playwright simpleUserStory.spect.ts to cover this case. This will require a snapshot update. What do you think?

Sounds good! I will make an update to fix this and will let you update the snapshot. Please stay tuned~

Replaced next <Head> with html <head> in preview to resolve font not updating issue. Updated Playwright user story regressing test and snapshot to cover this weak point. Updated select wrapper component to be more accessible and compatible with Playwright.

Not sure why config panel width changed after editing component, thus
had to update one UI snapshot as well.

Further polished pnpm scripts to better match actual flag name, i.e.
pnpm test:e2e:update-snapshots to match playwright test
--update-snapshots (with an 's')
@KemingHe
Copy link
Collaborator Author

@wei , my latest commit is a (like you said) "bad practice" fix, as it uses the html <head> in preview.tsx. Still, please use the updated user story snapshots to confirm your better solution. Excited for the great news.

@wei wei force-pushed the upgrade-pagarouter2approuter-keminghe branch from 797d168 to 4030c8e Compare December 19, 2024 03:01
@wei wei force-pushed the upgrade-pagarouter2approuter-keminghe branch from 4030c8e to b809885 Compare December 19, 2024 03:02
@wei wei enabled auto-merge (squash) December 19, 2024 03:03
Copy link
Owner

@wei wei left a comment

Choose a reason for hiding this comment

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

@KemingHe ✅ Approved!! I'm so excited.

@wei wei merged commit d73c1be into wei:master Dec 19, 2024
7 checks passed
@wei wei mentioned this pull request Dec 19, 2024
@KemingHe KemingHe deleted the upgrade-pagarouter2approuter-keminghe branch December 19, 2024 04:32
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.

2 participants