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

Tauri + NextJS app directory using router.push from next/navigation doesn't render page correctly #48642

Open
1 task done
Royceb opened this issue Apr 20, 2023 · 13 comments
Open
1 task done
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@Royceb
Copy link

Royceb commented Apr 20, 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.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 7.24.2
    Relevant packages:
      next: 13.3.1-canary.16
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

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

App directory (appDir: true), Routing (next/router, next/navigation, next/link), Static HTML Export (output: "export")

Link to the code that reproduces this issue

https://github.com/Royceb/nextjs-app-dir-tauri-router-push-example

To Reproduce

  1. Ran npx create-next-app@latest --experimental-app

  2. Set up Tauri

    2.1: Ran pnpm add -D @tauri-apps/cli

    2.2: Added tauri to package.json scripts. Ran pnpm tauri init.

  3. Updated next.config.js to use output: "export" for SSG (Static Generation).

  4. Made a simple page at app/examplePage/page.tsx

  5. Imported next/navigation in app/page.tsx and added a button that calls router.push('/examplePage').

  6. Ran pnpm tauri dev and clicked the button. The app navigated to the example page as expected and rendered it properly.

  7. Ran pnpm tauri build and opened the app. Clicked the button. The app did naviate to the example page, but it did not render it properly. The page rendered code as text instead of rendering the page.

Describe the Bug

I was uncertain whether to open this in Tauri or NextJS, so I opened issues in both platforms.

While utilizing a NextJS application, version 13, and the experimental app directory, I encountered an issue where using router.push to navigate to a new page fails to render correctly. Although the navigation occurs successfully, the page only displays code as text instead of rendering the expected content. I have not found any console logs or errors related to this issue.

This problem only arises after building and running the application. Locally, everything seems to be functioning correctly.

Recording: https://user-images.githubusercontent.com/3469263/233444738-73f955e9-2aae-43fb-a92b-d0a4c1dd3c3e.mov

Screenshot: image

Expected Behavior

The page should render correctly.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@Royceb Royceb added the bug Issue was opened via the bug report template. label Apr 20, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Apr 20, 2023
@reyamir
Copy link

reyamir commented Apr 21, 2023

confirmed, I have same issue in my app

@reyamir
Copy link

reyamir commented Apr 21, 2023

same issue with <Link> component, but if we add prefetch={false}, it work fine

@reyamir
Copy link

reyamir commented Apr 21, 2023

I don't know why, but {forceOptimisticNavigation: true} to router.push is fixed this issue

@reyamir
Copy link

reyamir commented Apr 21, 2023

nope, this still temp solution, add forceOptimisticNavigation will force hard navigation

@reyamir
Copy link

reyamir commented Apr 21, 2023

hey @Royceb , please reopen this issue, we need official fix, instead of tricky solution

@Royceb Royceb reopened this Apr 21, 2023
@Kazzuk
Copy link

Kazzuk commented Apr 23, 2023

Confirmed I’m also facing the same issue when using the Link component.

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Home
Binaries:
  Node: 18.16.0
  npm: N/A
  Yarn: N/A
  pnpm: 8.3.1
Relevant packages:
  next: 13.3.1
  eslint-config-next: 13.3.1
  react: 18.2.0
  react-dom: 18.2.0

@brillout

This comment was marked as off-topic.

@jlarmstrongiv
Copy link
Contributor

It seems the forceOptimisticNavigation workaround will be removed soon #47905

@Kazzuk
Copy link

Kazzuk commented Apr 25, 2023

This pull request #48383 could be related to the issue, yet to test before this pull request.

@Royceb
Copy link
Author

Royceb commented Apr 25, 2023

This pull request #48383 could be related to the issue, yet to test before this pull request.

I tried with the latest canary (13.3.2-canary.6) and still had the same issue.

@Kazzuk
Copy link

Kazzuk commented Apr 27, 2023

This pull request #48383 could be related to the issue, yet to test before this pull request.

I tried with the latest canary (13.3.2-canary.6) and still had the same issue.

Can you try 13.3.2-canary.10? Someone made a change regarding making prefetch not async

@Royceb
Copy link
Author

Royceb commented Apr 27, 2023

This pull request #48383 could be related to the issue, yet to test before this pull request.

I tried with the latest canary (13.3.2-canary.6) and still had the same issue.

Can you try 13.3.2-canary.10? Someone made a change regarding making prefetch not async

No luck with 13.3.2-canary.10.

@reupen
Copy link

reupen commented Jun 1, 2023

I did some further investigation here: tauri-apps/tauri#6762 (comment)

In short, the content-type response header for the .txt file is not set. That causes Next.js to navigate to the .txt file when the route is opened.

The behaviour could be improved on both sides IMO – is it necessary to do that because the content type is not set?

The relevant code in Next.js is here:

const contentType = res.headers.get('content-type') || ''
let isFlightResponse = contentType === RSC_CONTENT_TYPE_HEADER
if (process.env.NODE_ENV === 'production') {
if (process.env.__NEXT_CONFIG_OUTPUT === 'export') {
if (!isFlightResponse) {
isFlightResponse = contentType.startsWith('text/plain')
}
}
}
// If fetch returns something different than flight response handle it like a mpa navigation
// If the fetch was not 200, we also handle it like a mpa navigation
if (!isFlightResponse || !res.ok) {
return [res.url, undefined]
}

Thanks

kino-ma added a commit to nkzwlab/ldap-portal that referenced this issue Nov 30, 2023
with prefetch, `router.push("/")` gets not working

refs: vercel/next.js#48642 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests

6 participants