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

fix(react-router): remove unnecessary load call after redirect #1662

Closed
wants to merge 1 commit into from

Conversation

freshgiammi
Copy link
Contributor

@freshgiammi freshgiammi commented May 24, 2024

Possibly fixes #1650

Copy link

vercel bot commented May 24, 2024

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

Name Status Preview Comments Updated (UTC)
start-basic ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2024 11:22am

Copy link

nx-cloud bot commented May 24, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit e98498c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx affected --targets=test:format,test:eslint,test:unit,test:build,build --parallel=3
✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

@schiller-manuel
Copy link
Contributor

can you add a test for this?

@freshgiammi
Copy link
Contributor Author

@schiller-manuel I tried making a test but I'm getting some error at type level, and I also can't replicate the issue within the test itself when the patch is not applied 🤔 hitting a bit of a wall right now, you have any ideas?

@samchouse
Copy link

samchouse commented May 27, 2024

Just wanted to confirm that running this PR as a patch does fix my context issues 🥳. Great work!

Edit: my issue partially came back, maybe 2 different instances of context undefined in my app

@SeanCassiere
Copy link
Member

Tested this PR locally and it doesn't seem to address the issue mentioned in #1650.

@freshgiammi
Copy link
Contributor Author

Tested this PR locally and it doesn't seem to address the issue mentioned in #1650.

IIRC it did fix the issue in the reproduction template for me. However context seems to be very delicate so it might only have fixed this partially.

I should have some bandwidth to check back on this in the weekend or early next week (and redo tests based on #1708).

@SeanCassiere
Copy link
Member

@freshgiammi

If it helps, I've got a test setup in #1713 that correctly break the route context during redirection.

@freshgiammi
Copy link
Contributor Author

freshgiammi commented Jun 11, 2024

@SeanCassiere Okay, so I tested this again and it does seem to fix the issue in the reproduction template for me: however, on a more careful look I see this controlled promise always getting rejected after the redirect, and I think the cause is likely this extra load call.

In the reproduction case we're navigating twice: once on initialization, and once more on redirect. However, the load() call is executed three times as the this.navigate call already calls load() for us here: calling it again just replaces the promise, making it invalid once the loadMatches function is executed.

Now, you've already included the previous changes here in #1713 via 6c1f633: these are good to have but they're probably not the real culprit here, so I'm changing this PR to only address this issue's likely root cause.

EDIT: Applying this patch on top of #1713:

Before:

Test Files  2 failed | 26 passed (28)
      Tests  14 failed | 379 passed (393)

After:

 Test Files  1 failed | 27 passed (28)
      Tests  2 failed | 391 passed (393)

@freshgiammi freshgiammi changed the title fix(react-router): improve route context assignment and delay store update fix(react-router): remove unnecessary load call after redirect Jun 11, 2024
SeanCassiere added a commit that referenced this pull request Jun 11, 2024
The patch implemented by @freshgiammi in #1662

Co-Authored-By: Gianmarco Rengucci <16855748+freshgiammi@users.noreply.github.com>
@SeanCassiere
Copy link
Member

@freshgiammi I've applied your fixes to #1713 and it looks good! 🎉

@freshgiammi
Copy link
Contributor Author

@SeanCassiere Great! I'll close this PR then and we can merge it via #1713 👍

SeanCassiere added a commit that referenced this pull request Jun 12, 2024
…lled after a redirection (#1713)

* test(react-router): adjust the test names to accomodate the on-navigate stuff

* test(react-router): breaking route context

* test(react-router): test cases for redirects breaking

* test(react-router): use a bit more sleep

* test(react-router): a bit clearer on whats being tested

* test(react-router): check the `window.location.pathname` in the tests

* fix(react-router): a single test is now working, dont know what that means

* test: make sure StrictMode is ON

* test(react-router): this is no longer needed since we are doing this in routeContext.test.tsx

* test(react-router): confirm StrictMode on

* test(react-router): adjust the test names to accomodate the on-navigate stuff

* test(react-router): breaking route context

* test(react-router): test cases for redirects breaking

* test(react-router): use a bit more sleep

* test(react-router): a bit clearer on whats being tested

* test(react-router): check the `window.location.pathname` in the tests

* fix(react-router): a single test is now working, dont know what that means

* test: make sure StrictMode is ON

* test(react-router): this is no longer needed since we are doing this in routeContext.test.tsx

* test(react-router): confirm StrictMode on

* test: wrap fireEvent calls in `act`

* chore: readability

* fix: i dont know why, but this fixes the tests

* test: turn these back on

* fix: lets not change too much

* fix: bit closer to what it was before

* chore: not over updating

reducing the updates like @freshgiammi PR

* test(react-router): route context breaking for layout routes

* test(react-router): cases testing route context in layout routes for `beforeLoad`, `loader`, and `useRouteContext`

* chore: use the useRouteContext hook from the route definition

* chore: mistake in the test

* test: wrap the render calls in `act`

* test: wrap createRouter in `act`

* test: remove magic sleeps

* test: nested routes

* test: loaders

* test: failing tests for the loaders

* test: react strictmode for loaders

* test: dont use `waitFor` rather wait for elements in the DOM

* test: more async-work delayed checking of route context

* test: add an invalidate call after

* fix: remove the recursive `this.load()` call

The patch implemented by @freshgiammi in #1662

Co-Authored-By: Gianmarco Rengucci <16855748+freshgiammi@users.noreply.github.com>

* refactor: restore the `checkLatest()` call here

* test: remove these tests for routeContext in redirects

---------

Co-authored-by: Gianmarco Rengucci <16855748+freshgiammi@users.noreply.github.com>
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.

Undefined context after redirect with wrapInSuspense at root route (introduced in 1.33.6)
4 participants