next.js icon indicating copy to clipboard operation
next.js copied to clipboard

After refresh, browser back button is not working.

Open dengdengyee opened this issue 7 years ago • 15 comments

Bug report

Describe the bug

After refresh, browser back button is not working.

To Reproduce

It even reproduces on now.sh!

  1. Go to https://zeit.co/home
  2. Click on top left "pricing" navigation button
  3. Browser refresh with cmd + r
  4. Browser back button -> It just stays still.

Expected behavior

It should go back to '/home'

Screenshots

Nov-11-2019 17-10-38

System information

  • OS: macOS Catalina 10.15
  • Browser : Chrome(Version 78.0.3904.97 (Official Build) (64-bit)) and safari(Version 13.0.2 (15608.2.30.1.1)) both reproduces this issue.
  • Version of Next.js: I checked the latest version also reproduces this issue.

Additional context

I can also reproduce with this example repo, which uses the latest next.js

npx create-next-app --example hello-world hello-world-app

dengdengyee avatar Nov 11 '19 08:11 dengdengyee

Thanks for reporting this!

Timer avatar Nov 11 '19 23:11 Timer

checked it on 8.1.1-canary.39 works there. so it only broke recently.

Devisione avatar Nov 17 '19 13:11 Devisione

9.1.4-canary.7 works fine!

Devisione avatar Nov 18 '19 08:11 Devisione

9.2.2 also has this bug ~

kxcy001123 avatar Mar 04 '20 10:03 kxcy001123

@kxcy001123 we have a regression test for this now which is passing. Can you provide additional details where you are seeing this behavior?

ijjk avatar Mar 04 '20 17:03 ijjk

i am using next.js with ant-design ui.

import { Layout } from 'antd';
 const Index = () => {
  console.log('pages index');

  return (
    <div>
      <Layout>
        <Link href="/userList">
          <span>userList</span>
        </Link>
      </Layout>
    </div>
  );
};

it is not working

but:

const Index = () => {
  console.log('pages index');

  return (
    <div>
      <div>
        <Link href="/userList">
          <span>用户列表页</span>
        </Link>
      </div>
    </div>
  );
};

it is ok; i dont understand 未命名

kxcy001123 avatar Mar 05 '20 02:03 kxcy001123

https://github.com/zeit/next.js/issues/9378#issuecomment-594993962

i knew it if some css in index.tsx. this bug can be reproduced

image

kxcy001123 avatar Mar 05 '20 03:03 kxcy001123

@kxcy001123 it sounds like the error you are seeing is this one: https://github.com/zeit/next-plugins/issues/282 which is resolved for CSS and SCSS with the built-in support. It looks you are using LESS though which requires the workaround of importing a .less file in _app

ijjk avatar Mar 05 '20 05:03 ijjk

@kxcy001123 it sounds like the error you are seeing is this one: zeit/next-plugins#282 which is resolved for CSS and SCSS with the built-in support. It looks you are using LESS though which requires the workaround of importing a .less file in _app

resolve my problem, ths

kxcy001123 avatar Mar 05 '20 05:03 kxcy001123

Not really a NextJS issue but hopefully could help someone how's reading this 👀

The backward navigation of my app would stop working out of the blue: I would hit back (either browser of router.back()), the url would change but the page would not. After hours of debugging and many coffees later I realised that a library I am using was setting history.state to null for the route where history.back would stop working. Removing that logic restored the correct behaviour.

Definitely a problem caused by external logic but I am wondering whether Next could be louder about it and possibly log an error 🤔 - thoughts?

steedems avatar Nov 04 '20 12:11 steedems

10.0.6 has this bug too

volcie avatar Mar 21 '21 06:03 volcie

I'm on Next 10.1.3 and facing similar symptoms. I'm not sure it's the same cause, but it may be related. I'm using emotion and extractCritical in a custom document like this:

  static async getInitialProps(ctx: DocumentContext) {
    const initialProps = await Document.getInitialProps(ctx);
    const styles = extractCritical(initialProps.html);
    return {
      ...initialProps,
      styles: (
        <>
          {initialProps.styles}
          <style
            dangerouslySetInnerHTML={{ __html: "html, body { margin: 0; }" }}
          />
          <style
            data-emotion-css={styles.ids.join(" ")}
            dangerouslySetInnerHTML={{ __html: styles.css }}
          />
        </>
      )
    };
  }

My issue manifest in a slightly different way in that 'back' works for every page except the 'landing' page. For example, if I directly navigate to '/', then click a lick to '/1', then back, it will fail. If I manually navigate to '/1' and then click a link to '/2', then back, it will fail. However, if I manually navigate to '/', then click '/1' followed by '/2', clicking back will correctly take me to '/1', but clicking back again will fail. This behavior is consistent across my site regardless of the starting location. I also cannot reproduce it in dev mode.

Also this seems to affect "Forward" equally. E.g. go to '/' -> '/1' -> '/2' (refresh) (back) (forward) <--- fails

nihakue avatar Apr 19 '21 11:04 nihakue

Got the same problem:

localhost/home -- <Link> --> localhost/test *Refresh* *Back Button*

tabname, location and history changes, but the window keeps the content of localhost/test

After poking around and piecemeal eliminating all possibilities, I came to the conclusion that createPortal (in a Modal component) is breaking my Next.JS app. After removing createPortal, everyting worked as expected.

Maybe some of you having the same issue.

Are the core-devs aware of issues related with createPortal? @timneutkens @Timer

Sorry, false alarm, was using 10.0.9. Whatever this was, seems to be fixed with 10.2.0

hedwiggggg avatar May 03 '21 17:05 hedwiggggg

Problem is still here, after page is cached it doesn't wanna show content related to page "next": "^11.0.1-canary.8",

ImTemporaryHere avatar Aug 05 '21 21:08 ImTemporaryHere

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

balazsorban44 avatar Jan 28 '22 00:01 balazsorban44