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(router): prevent multiple navigation at the same time #1895

Merged
merged 7 commits into from
Feb 29, 2024

Conversation

aegenet
Copy link
Contributor

@aegenet aegenet commented Feb 1, 2024

Pull Request

πŸ“– Description

When a user clicks quickly from one page to another, the content can be duplicated.

🎫 Issues

Resolves #1860.

πŸ‘©β€πŸ’» Reviewer Notes

I prevent multiple navigations from occurring simultaneously and store the most recent one. This ensures that users don't find it odd to end up on their last desired page.

I was delayed in creating this PR because I noticed another issue with the error handling in @aurelia/router. However, it requires a separate issue/PR, as it's not just linked to this current issue.

πŸ“‘ Test Plan

  • Added new integration/e2e tests for this specific case.

⏭ Next Steps

When a user clicks quickly from one page to another, the content can be duplicated

close aurelia#1860
@bigopon bigopon requested a review from jwx February 1, 2024 09:51
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 88.46%. Comparing base (06aa113) to head (84779a8).
Report is 2 commits behind head on master.

Files Patch % Lines
packages/router/src/router.ts 94.73% 1 Missing ⚠️
packages/router/src/utilities/runner.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1895      +/-   ##
==========================================
+ Coverage   88.37%   88.46%   +0.09%     
==========================================
  Files         260      260              
  Lines       22847    22862      +15     
  Branches     5300     5301       +1     
==========================================
+ Hits        20190    20226      +36     
+ Misses       2657     2636      -21     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@bigopon
Copy link
Member

bigopon commented Feb 28, 2024

@aegenet , thanks for the PR. It seems the fix does work, though not always. Sometimes the e2e tests passed, and sometimes it failed.

When some of the e2e tests failed, I can see this test result:

image

That test result means there's something that pulls back the URL from two-route to one-route, based on this code

    await Promise.all([
      page.waitForURL(`${baseURL}/pages/two-route`),
      page.click('#page-two-link'),
    ]);

    expect(page.url()).toBe(`${baseURL}/pages/two-route`); // <<<<<<< fails here

I've checked the fix, it seems ok, so I'm not sure what could be the reason.

cc @jwx

@bigopon
Copy link
Member

bigopon commented Feb 29, 2024

When running locally, without the commits from master which has the changes at #1900, I also experienced the same failure, even though it's really rare. I'm not sure whether this is a playwright thing.

@aegenet
Copy link
Contributor Author

aegenet commented Feb 29, 2024

@bigopon I remember there was an issue with the unit test. I think it's the same issue... and yes, it's the same: Playwright doesn't wait for the end of the navigation, so we need to wait for the end of all navigation before navigating to the last requested page.

@bigopon
Copy link
Member

bigopon commented Feb 29, 2024

@aegenet thanks for checking that.

Playwright doesn't wait for the end of the navigation

Can this actually affect the test? Once the url has been changed to two-route, can it go back to one-route via something inside a navigation (or latest navigation), briefly or eventual back to two-route?

@aegenet
Copy link
Contributor Author

aegenet commented Feb 29, 2024

Yes, I think, because we do a lot of navigation (page-one-link, page-two-link, & auth-link etc), so after, when we execute the following statement:

await Promise.all([
  page.waitForURL(`${baseURL}/pages/two-route`),
  page.click('#page-two-link'),
]);

The:

page.waitForURL(`${baseURL}/pages/two-route`)

can be swallowed by the previous loop "click"

At the moment, I can't reproduce the issue anymore with my last commit.

@bigopon
Copy link
Member

bigopon commented Feb 29, 2024

That sounds like inside a navigation the URL would be updated somehow, I'm not sure on this, but the fix isn't doing any related to that behavior so I think it's ok. Thanks @aegenet.

@bigopon bigopon merged commit deed11e into aurelia:master Feb 29, 2024
26 checks passed
@bigopon
Copy link
Member

bigopon commented Feb 29, 2024

Nice work, thanks @aegenet

@bigopon
Copy link
Member

bigopon commented Feb 29, 2024

If you wanna test this out, our dev version should be on npm in about 15 mins @aegenet

@aegenet
Copy link
Contributor Author

aegenet commented Mar 1, 2024

It's ok with the dev version: https://gist.dumber.app/?gist=93e7586ed697b010ed48517e7ad3c423

No more 'clone wars', thanks for your review and involvement.

@aegenet aegenet deleted the fix/router-dup-content-1860 branch March 1, 2024 07:31
AureliaEffect pushed a commit that referenced this pull request Mar 2, 2024
2.0.0-beta.12 (2024-03-02)

**BREAKING CHANGE:**

* **enhance:** call app tasks with `.enhance` API, return app root instead of controller (#1916) ([4d522b2](4d522b2))
* **au-compose:** always create host for non custom element composition (#1906) ([8a28e0a](8a28e0a))

**Features:**

* **au-compose:** ability to compose string as element name (#1913) ([06aa113](06aa113))

**Bug Fixes:**

* **router:** prevent multiple navigation at the same time (#1895) ([deed11e](deed11e))
* **router:** properly handle false in conditional router hooks (#1900) ([a671463](a671463))
* **di:** dont jit register resources ([8ffde34](8ffde34))
* **di:** new instance resolver (#1909) ([efe208c](efe208c))
* **runtime:** tweak typings of injectable token ([89f76eb](89f76eb))

**Refactorings:**

* **runtime:** delay overriding array prototypes (#1914) ([d8be144](d8be144))
* **router:** use resolve ([89f76eb](89f76eb))
* **runtime:** better type inferrence for injectable token ([89f76eb](89f76eb))
* **di:** simplify container has, cleanup router ([89f76eb](89f76eb))

**Docs:**

* **docs:** add JS examples using resolve for IHttpClient (#1907) ([d57c1f1](d57c1f1))
* **doc:** remove define hook from documentation (#1903) ([f684141](f684141))
@bigopon
Copy link
Member

bigopon commented Mar 3, 2024

Thank you too @aegenet for the work and the confirmation πŸ™

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.

Aurelia Router - Duplicate content
2 participants