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

Docs: using example code from app router 'error handling' page seems to trigger NEXT_TS_ERRORS.INVALID_CLIENT_ENTRY_PROP warning #46843

Closed
philwolstenholme opened this issue Mar 6, 2023 · 9 comments
Labels
Documentation Related to Next.js' official documentation. TypeScript Related to types with Next.js.

Comments

@philwolstenholme
Copy link
Contributor

philwolstenholme commented Mar 6, 2023

What is the improvement or update you wish to see?

Copying this example from https://beta.nextjs.org/docs/routing/error-handling into a file called src/app/(main)/product/[id]/error.tsx:

'use client'; // Error components must be Client components

import { useEffect } from 'react';

export default function Error({
  error,
  reset,
}: {
  error: Error;
  reset: () => void;
}) {
  useEffect(() => {
    // Log the error to an error reporting service
    console.error(error);
  }, [error]);

  return (
    <div>
      <h2>Something went wrong!</h2>
      <button
        onClick={
          // Attempt to recover by trying to re-render the segment
          () => reset()
        }
      >
        Try again
      </button>
    </div>
  );
}

Results in a Props must be serializable for components in the "use client" entry file, "reset" is invalid.ts TypeScript warning from the packages/next/src/server/typescript/rules/client-boundary.ts rule.

Is there any context that might help us understand?

I copied the code as-is from the docs and got the warning

Does the docs page already exist? Please link to it.

https://beta.nextjs.org/docs/routing/error-handling

@philwolstenholme philwolstenholme added the Documentation Related to Next.js' official documentation. label Mar 6, 2023
@github-actions github-actions bot added the TypeScript Related to types with Next.js. label Mar 6, 2023
@philwolstenholme philwolstenholme changed the title Docs: using example code from app router 'error handling' page triggers NEXT_TS_ERRORS.INVALID_CLIENT_ENTRY_PROP Docs: using example code from app router 'error handling' page seems to trigger NEXT_TS_ERRORS.INVALID_CLIENT_ENTRY_PROP warning Mar 6, 2023
@MahirPatel3130
Copy link

maybe the problem is that reset function is not get serialized when it gets passed as props, so maybe you can useCallback() hook by which same function instance on subsequent renders as long as its dependencies have not changed.

@MahirPatel3130
Copy link

Screenshot 2023-03-06 at 2 21 48 PM

@MahirPatel3130
Copy link

You can try this out maybe this can work.

@bramarcade
Copy link

I'm having the same problem. (I tried using a callback and that didn't work either.)

Is there a way to declare a client component such that it can only accept props from other client components? That would obviate the serializability concern and probably stop the warning.

@philwolstenholme
Copy link
Contributor Author

I wonder if this is related to this other issue that I am having? #46637 (comment)

@MahirPatel3130
Copy link

I'm having the same problem. (I tried using a callback and that didn't work either.)

Is there a way to declare a client component such that it can only accept props from other client components? That would obviate the serializability concern and probably stop the warning.

RIght now, maybe there is not any way to declare other client component since as we know that the problem is in reset function which is not get serialzied either way.

@MahirPatel3130
Copy link

So, maybe right now it's better to wait for the version 13 get production ready first because still the docs is unclear and not completely correct.

@philwolstenholme
Copy link
Contributor Author

Ah, this issue is a duplicate of #46573, which is now fixed (I guess the fix will be in the next release)

@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2023

This closed issue has been automatically locked because it had no new activity for a month. 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 locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Related to Next.js' official documentation. TypeScript Related to types with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants