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

storeCodeFromRoute route object without host breaks loop #3576

Closed
2 of 5 tasks
rain2o opened this issue Sep 18, 2019 · 3 comments
Closed
2 of 5 tasks

storeCodeFromRoute route object without host breaks loop #3576

rain2o opened this issue Sep 18, 2019 · 3 comments
Assignees
Labels
bug Bug reports P3: Normal Priority mark - normal priority
Milestone

Comments

@rain2o
Copy link
Contributor

rain2o commented Sep 18, 2019

Current behavior

In core/lib/multistore.ts::storeCodeFromRoute if matchedRouteOrUrl is an object but is missing the host property, the current logic simply returns an empty string if the first store in the store loop does not match. The logic is basically the following:

  1. Iterate all stores from mapStoreUrlsFor
  2. In each iteration, create normalizedPath from matchedRouteOrUrl.path (if object)
  3. If normalizedPath doesn't match the store code in the current iteration, check if matchedRouteOrUrl is an object.
  4. If it IS an object, and it doesn't have ['host'] then return ''.

The problem here is only the first store is checked under these conditions. The specific scenario where I discovered this is when I am on a product view and I try to load it server side, it fails and redirects to page not found. I'm not sure why the route object doesn't have host, but this is what's causing this break in the loop.

Expected behavior

It should follow the same logic as when matchedRouteOrUrl is a string. So instead of return '', it should either continue, or set url = normalizedPath.

Steps to reproduce the issue

I'm not sure if there's something in our environment that is causing this scenario to work this way, but how we produced it is:

  1. Enable multistore with at least two stores active.
  2. Go to a product view on a store that is 2nd or later in the list of mapStoreUrlsFor.
  3. Refresh the page.

Repository

Can you handle fixing this bug by yourself?

  • YES
  • NO

Which Release Cycle state this refers to? Info for developer.

Pick one option.

  • This is a bug report for test version on https://test.storefrontcloud.io - In this case Developer should create branch from develop branch and create Pull Request 2. Feature / Improvement back to develop.
  • This is a bug report for current Release Candidate version on https://next.storefrontcloud.io - In this case Developer should create branch from release branch and create Pull Request 3. Stabilisation fix back to release.
  • This is a bug report for current Stable version on https://demo.storefrontcloud.io and should be placed in next stable version hotfix - In this case Developer should create branch from hotfix or master branch and create Pull Request 4. Hotfix back to hotfix.

Environment details

  • Node: 10.16
  • Code Version: v1.10.2
@rain2o rain2o added the bug Bug reports label Sep 18, 2019
@pkarw pkarw added this to the 1.11.0-rc.1 milestone Sep 18, 2019
@pkarw pkarw added the P3: Normal Priority mark - normal priority label Sep 18, 2019
@pkarw
Copy link
Collaborator

pkarw commented Sep 18, 2019

@alinadivante we need to confirm this issue on both: 1.10.x and 1.11

@alinadivante
Copy link
Collaborator

On 1.10.2 I have a different problem. When I try to open product details page (or category page), I am redirected to page without content,
image

after refreshing the page I see the following error in the dev console.
image

@andrzejewsky
Copy link
Contributor

I was looking at this function and this return when there is no host is unnecessary and it breaks the loop as you @rain2o mentioned. We can even delete it because when there is no matches at the end function returns empty string. Deleting this line solves the problem. I'll prepare PR with a little bit refactoring this one & check if everything works properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports P3: Normal Priority mark - normal priority
Projects
None yet
Development

No branches or pull requests

4 participants