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

chore: react-server (dynamic ssr and rsc) error handling e2e tests #1112

Merged
merged 15 commits into from
Jan 4, 2025

Conversation

rmarscher
Copy link
Contributor

@rmarscher rmarscher commented Dec 31, 2024

The additional ErrorFallback and Suspense examples seem to work well.

The tests I added for using the browser back button and for throwing an exception from a server function are failing though.

ref: #967

Copy link

vercel bot commented Dec 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
waku ⬜️ Ignored (Inspect) Visit Preview Jan 4, 2025 10:40am

Copy link

codesandbox-ci bot commented Dec 31, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@rmarscher
Copy link
Contributor Author

We need a test case for fs router that calls a server function that throws. I think that will demonstrate the default <h1>Not Found</h1> error boundary in the router code. Should we create a new fixture or add to the use-router fixture and test suite?

@tylersayshi
Copy link
Contributor

tylersayshi commented Dec 31, 2024

Should we create a new fixture or add to the use-router fixture and test suite?

Does this also happen with just createPages? Or is it specific to fs-router?

@rmarscher
Copy link
Contributor Author

rmarscher commented Dec 31, 2024

Should we create a new fixture or add to the use-router fixture and test suite?

Does this also happen with just createPages? Or is it specific to fs-router?

Ah right... the server function errors hit the ErrorBoundary for the Router component (import { Router } from 'waku/router/client'). So that should be the same with createPages.

edit: I'll try adding a test to create-pages.spec.ts.

@dai-shi dai-shi mentioned this pull request Jan 1, 2025
@rmarscher rmarscher force-pushed the chore/react-server-error-tests branch from 84ee3d5 to 99fed9d Compare January 3, 2025 07:14
@rmarscher
Copy link
Contributor Author

rmarscher commented Jan 3, 2025

edit: I'll try adding a test to create-pages.spec.ts.

I added tests in 99fed9d. The create-pages.spec.ts tests pass since they demonstrate the current behavior. The rsc-basic.spec.ts doesn't seem to catch the thrown server function error yet. [edit: It works! I think forgot to run pnpm run compile locally to rebuild waku after pulling.] Thanks for working on it @dai-shi!

@rmarscher
Copy link
Contributor Author

Here are the remaining failing tests that I added:

create-pages.spec.ts:91 › server function unreachable
Empty blank shown after attempting to call unreachable server function (createPages / Router).

rsc-basic.spec.ts:74 › server handle network errors
Empty blank shown after attempting to call unreachable server function (minimal API).

ssr-catch-error.spec.ts:41 › navigate back after invalid page through client router
"Home Page" header not visible. Page has "Unauthorized" header instead.

@dai-shi
Copy link
Owner

dai-shi commented Jan 3, 2025

The create-pages.spec.ts tests pass since they demonstrate the current behavior.

Should we fix it for the expected behavior?

ssr-catch-error.spec.ts

I'm currently working on this. This requires to change the way how we code. But, this is something I've been wondering, and the outcome will be more reasonable.

I'll check out other cases later. Thanks so much for helping this.

@rmarscher
Copy link
Contributor Author

rmarscher commented Jan 3, 2025

The create-pages.spec.ts tests pass since they demonstrate the current behavior.

Should we fix it for the expected behavior?

Yes, we should. With the server function unreachable test, we should see what error is caught by the error boundary for network errors and render a different message than Not Found.

The error seems to happen outside the layout/page render trees so it doesn't hit any of the developer defined error boundaries. I think we need a way to pass an ErrorBoundary into the <Router /> component as a prop so we can define custom behavior. Or maybe we can get an ErrorBoundary in _root.tsx to capture all errors like this. That would be pretty intuitive and not require a custom main.tsx.

@dai-shi
Copy link
Owner

dai-shi commented Jan 4, 2025

I'm currently working on this.

Hm, maybe I should work on the create-pages one first.

@dai-shi
Copy link
Owner

dai-shi commented Jan 4, 2025

8fa1216 @rmarscher Can you check it? If you want to show the error boundary, you should "throw" the error in render instead of displaying.

we should see what error is caught by the error boundary for network errors

Note that server actions are not part of rendering, so it's not something to catch.

Maybe we should add a new test for unreachable with rendering. You already have it: 'server page unreachable'

render a different message than Not Found.

Yeah, keep this mind and we should tackle it later.

@dai-shi
Copy link
Owner

dai-shi commented Jan 4, 2025

@rmarscher I haven't received your review yet, but this is done. I'll merge it anyway, but feel free to review, discuss, and ask questions if any.

Two remaining things:

  1. The default fallback <h1>Not Found</h1> is not appropriate.
  2. Needs refactors as some code is no longer used.

I'll work on 2 first.

@dai-shi dai-shi marked this pull request as ready for review January 4, 2025 10:47
@dai-shi dai-shi merged commit d96462a into dai-shi:main Jan 4, 2025
26 checks passed
@dai-shi dai-shi mentioned this pull request Jan 4, 2025
@dai-shi
Copy link
Owner

dai-shi commented Jan 4, 2025

Both remaining tasks should be done in #1122.

@rmarscher
Copy link
Contributor Author

Oh great. Sorry I missed reviewing the other updates. I'll take a look. Thank you!

dai-shi added a commit that referenced this pull request Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants