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

next/image preload not working as expected in AppDir. Affecting LCP and FP. Order of preload is different than page-dir. #52995

Closed
1 task done
gauravsaini964 opened this issue Jul 21, 2023 · 11 comments
Assignees
Labels
Image (next/image) Related to Next.js Image Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@gauravsaini964
Copy link

gauravsaini964 commented Jul 21, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:19 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8103
    Binaries:
      Node: 16.20.0
      npm: 8.19.4
      Yarn: 1.22.19
      pnpm: 8.6.0
    Relevant Packages:
      next: 13.4.11
      eslint-config-next: 13.4.11
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

Image optimization (next/image, next/legacy/image)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/gauravsaini964/image-preload-next13

To Reproduce

  1. Build the repo.
  2. Navigate to index page (which is using app-dir) and inspect index.html code.
  3. Image preload statement is after font,css,webpack and 2-3 other chunks.
  4. Navigate to /page-dir (which is using page dir) and repeat step 2 & 3.
  5. Image preload is before all other preload tags.

Describe the Bug

Order of image preload tag in app-dir is different from what it used to be in pages-dir and hence FP and LCP metric is getting affected. Same is replicated in lighthouse scores.
Compare following screenshots:

Screenshot 2023-07-21 at 4 21 41 PM Screenshot 2023-07-21 at 4 23 43 PM Screenshot 2023-07-21 at 4 34 31 PM Screenshot 2023-07-21 at 4 30 13 PM Screenshot 2023-07-21 at 4 33 29 PM Screenshot 2023-07-21 at 4 31 05 PM

Expected Behavior

Image preload tag should come above every other preload tag imo as it is giving me best performance.

I have a ecommerce app which has 1800+ pages built with both app-router and page-router. App router app is faster in every aspect apart from FP and LCP metric consistently by ~1seconds because that website has lot more scripts to preload.

Which browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

Vercel

NEXT-1463

@gauravsaini964 gauravsaini964 added the bug Issue was opened via the bug report template. label Jul 21, 2023
@github-actions github-actions bot added the Image (next/image) Related to Next.js Image Optimization. label Jul 21, 2023
@styfle styfle added kind: bug linear: next Confirmed issue that is tracked by the Next.js team. and removed bug Issue was opened via the bug report template. labels Jul 21, 2023
@styfle styfle self-assigned this Jul 21, 2023
@gauravsaini964
Copy link
Author

Any update or ETA on this?
Sitting on website that needs to go live.

Thanks for your efforts.

@styfle
Copy link
Member

styfle commented Jul 24, 2023

This is an issue in React.

I notified @gnoff who is going to fix it upstream.

@gauravsaini964
Copy link
Author

Hey @gnoff. Any issue, PR or ETA to track?

Thank you for your contributions.

@gauravsaini964

This comment was marked as spam.

@gnoff
Copy link
Contributor

gnoff commented Jul 26, 2023

No issue just yet but I think a general timeline of 2 weeks is reasonable. I'll try to update this issue with a link tracking the work once I get it started

@gauravsaini964
Copy link
Author

Please check #53574. If it is related or not.

@gauravsaini964
Copy link
Author

Hey @gnoff
Any progress on this? Thanks

@styfle
Copy link
Member

styfle commented Aug 7, 2023

I believe this is the upstream React PR:

kodiakhq bot pushed a commit that referenced this issue Aug 8, 2023
…#53700)

The root cause is `ReactDOM.preload()` inserts `<link rel="preload">` above the `<meta name="viewport">`. 

This PR adds a test to prove that upgrading React fixes the issue (see commits).

- Depends on facebook/react#27201
- Depends on #53742
- Fixes #53574
- Related #52995
@steve-marmalade
Copy link

Do we expect that this issue has been fixed since the upstream react fixes were included in 13.4.15 via #53881 ?

@styfle
Copy link
Member

styfle commented Aug 17, 2023

Confirmed this is fixed 👍

@styfle styfle closed this as completed Aug 17, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Sep 1, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Image (next/image) Related to Next.js Image Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

No branches or pull requests

4 participants