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

Routing: fix mis-ordered conditional for orgAddress #1457

Merged
merged 6 commits into from
Jul 6, 2020

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Jun 27, 2020

See https://sentry.io/share/issue/6f218cc4d1434b28b606e23b12b3f743/

Couldn't actually reproduce the error, but on inspection, it was clear the existence conditional (if (!orgAddress)) was placed too low.

Ended up making a slightly larger change, because it felt more clear to nest everything related to the 'org' mode in a code block.

@sohkai sohkai requested review from bpierre and andy-hook June 27, 2020 17:30
@auto-assign auto-assign bot requested a review from Evalir June 27, 2020 17:33
andy-hook
andy-hook previously approved these changes Jun 29, 2020
Copy link

@andy-hook andy-hook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! perhaps we should add some test cases to cover the various conditions?

Polishes the routing behaviour:
- Avoid double slashes (`//`) on home paths
- Avoid parsing label data from query strings if a preferences path
  isn't found
@sohkai
Copy link
Contributor Author

sohkai commented Jun 29, 2020

perhaps we should add some test cases to cover the various conditions

Good call! I've added tests for all the exposed internal functions for getting and parsing paths.

In the process, I found a few rough edges and smoothed them out: 36ea8c8.

More importantly, I found the real cause of the bug that is causing all permissions changes at the moment to fail: 7bf1714.


Let me know how this looks—can split out into separate PRs if we want to discuss / work on 36ea8c8 separately!

src/routing.js Outdated
}

return getPath({
...locator,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that we weren't passing along the locator.mode.orgAddress above, causing this to not produce the correct path in the signer panel.

Wasn't sure deep merging was the best approach vs. individually selecting the keys we expect, but felt like the most safe in case we add more keys to locator in the future.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well found! I think this is fine for now.

Copy link
Contributor

@bpierre bpierre Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m wondering if that could be an issue, since it now always extends locator. A change of mode (e.g. from org to onboarding) would copy the entries of the mode A into the mode B, and going the other way will copy entries (which might be undesired) from the mode B back into the mode A.

update() used to have an extend param to let people decide, but we ended up moving this on the consumer side to make it behave always the same: #1272 (comment)

The problem was that we weren't passing along the locator.mode.orgAddress above, causing this to not produce the correct path in the signer panel.

Do you know if the issue is related to mode not being properly extended in an update() call?

In any case, this is probably something that will keep happening, since we have these two nested objects. I think update() should let consumers either set or extend the mode and the preferences, independently or together. We could express this in different ways, but perhaps adding some validation / errors could be enough (e.g. if orgAddress is missing from an update)? Or should we provide a way to set / extend / reset any of the two components?

Edit: wondering if having an automatic inheritance of mode.orgAddress, like we already have for mode.name, would be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, as mentioned in #1457 (comment), it sounds like we should prefer to use the function variant of path() when we want to extend an existing mode.

What do you think about staying as close to React.setState()'s behaviour as possible then—if you change an object, you overwrite that object entirely (to the point where we don't even inherit mode.name)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about staying as close to React.setState()'s behaviour as possible then—if you change an object, you overwrite that object entirely (to the point where we don't even inherit mode.name)?

That sounds good yes. We could do this and also have errors?

  • When mode.name is not set.
  • When mode.orgAddress is not set (org mode).
  • When mode.instancePath is set without mode.instanceId (org mode).
  • When mode.status is not set (onboarding mode).
  • When preferences.subsection is set without preferences.section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, we would use log() for the errors?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of throwing? To make sure we don’t forget anything when updating the mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing an offline discussion, we decided to:

  • Log a warning
  • On production, send an error to sentry
    • Move the sentry configuration to be environment variable-controlled
    • Only initialize sentry on *.aragon.org domains (SENTRY_DOMAIN=*.aragon.org)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logged warnings in c88176d; will add the sentry bits in another PR.

Comment on lines +155 to +156
// Ignore labels if search does not contain a preferences path
const labels = searchParams.has('preferences')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

src/routing.js Outdated
}

return getPath({
...locator,
Copy link
Contributor

@bpierre bpierre Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m wondering if that could be an issue, since it now always extends locator. A change of mode (e.g. from org to onboarding) would copy the entries of the mode A into the mode B, and going the other way will copy entries (which might be undesired) from the mode B back into the mode A.

update() used to have an extend param to let people decide, but we ended up moving this on the consumer side to make it behave always the same: #1272 (comment)

The problem was that we weren't passing along the locator.mode.orgAddress above, causing this to not produce the correct path in the signer panel.

Do you know if the issue is related to mode not being properly extended in an update() call?

In any case, this is probably something that will keep happening, since we have these two nested objects. I think update() should let consumers either set or extend the mode and the preferences, independently or together. We could express this in different ways, but perhaps adding some validation / errors could be enough (e.g. if orgAddress is missing from an update)? Or should we provide a way to set / extend / reset any of the two components?

Edit: wondering if having an automatic inheritance of mode.orgAddress, like we already have for mode.name, would be enough?

@vercel vercel bot temporarily deployed to Preview July 6, 2020 19:07 Inactive
Copy link
Contributor

@bpierre bpierre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 💯 💯

@sohkai sohkai merged commit 82f4d5f into master Jul 6, 2020
@sohkai sohkai deleted the fix-routing-conditional branch July 6, 2020 20:02
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