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

_app context loses state when navigating back (looks like vercel only, 10.0.2^18) #19237

Closed
wiesson opened this issue Nov 17, 2020 · 3 comments · Fixed by vercel/vercel#5435
Closed
Assignees
Milestone

Comments

@wiesson
Copy link
Contributor

wiesson commented Nov 17, 2020

Bug report

Describe the bug

I have wrapped a context around _app and it looses it's state when I navigate back (via browser or <Link /> (at least I think that is the problem, might be introduced with #19006, but I'm also not 100% sure)

_app.js

import { ListContextProvider } from "../context";

function MyApp({ Component, pageProps }) {
  return (
    <ListContextProvider>
      <Component {...pageProps} />
    </ListContextProvider>
  );
}

Usage in List Component

const List = ({ items = [] }) => { // initial state comes from the parent component
  const context = useContext(ListContext);

  function loadMoreFn() {
    context.addFn([makeId(6), makeId(6), makeId(6), makeId(6)]); // just faking additional random data 
  }

  return (
    <>
      <div className={styles.grid}>
        {items.concat(context.items).map((item) => ( // yes, could also be done with useEffect and useState, but for simplicity 
          <Link href={`/detail/${item}`} key={item}>
            <a className={styles.card}>
              <h3>{item} &rarr;</h3>
            </a>
          </Link>
        ))}
      </div>

      <button onClick={loadMoreFn}>Load more</button>
    </>
  );
};

To Reproduce

Repo - https://github.com/wiesson/next-testing
Basic demo - https://next-testing-six.vercel.app

  1. Click on load more,
  2. Follow an item (loaded or existing)
  3. go back afterwards

Expected behavior

The state should not be cleared and it worked well before 10.0.2. It does not happen locally (next start), but on Vercel.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • Version of Next.js: 10.0.2^18
  • Deployment: Vercel
@wiesson wiesson added the bug Issue was opened via the bug report template. label Nov 17, 2020
@Timer Timer added this to the iteration 13 milestone Nov 17, 2020
@Timer Timer added kind: bug and removed bug Issue was opened via the bug report template. labels Nov 17, 2020
@wiesson wiesson changed the title _app context loses state when navigating back (looks like vercel only) _app context loses state when navigating back (looks like vercel only, 10.0.2^18) Nov 17, 2020
@Timer Timer added the point: 2 label Nov 17, 2020
@ijjk
Copy link
Member

ijjk commented Nov 17, 2020

HI, this should be corrected from the above PR now, please re-deploy your application and give it a try!

@wiesson
Copy link
Contributor Author

wiesson commented Nov 17, 2020

HI, this should be corrected from the above PR now, please re-deploy your application and give it a try!

Looks good!! Thank you very much! 🙌

@balazsorban44
Copy link
Member

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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants