-
Notifications
You must be signed in to change notification settings - Fork 15
File viewer: Support 'hashchange' navigation events #195
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a problem caused for using the hash routing rather than the browser routing. We use hash routing because Kyle ships the UI to one of his dashboards on S3.
I wonder if this change would be better suited at a higher point in the hierarchy of the tree since the diff viewer also suffers from this issue.
I wonder if this is better written with a higher order component and we can use it on routes.jsx to wrap DiffViewerContainer
and FileViewerContainer
.
Or perhaps withRouter
is all we would need:
https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/withRouter.md
A side note, I wonder if this:
<Route
path="/file"
component={FileViewerContainer}
/>
should have been written as this:
<Route
path="/file"
render={({ location }) => (
<FileViewerContainer
revision={location.search.revision}
path={location.search.path}
/>
)}
component={FileViewerContainer}
/>
This would simplify parseQueryParams() to no have to set the state as it currently does.
Thank you @armenzg for the review! But after doing some research, it seems that React's router actually does update on As this is already done elsewhere in the code, I'll change my fix to use |
Could it be that you are relying on query params to change the history when they are parsed separately from the hash? |
Apparently But maybe there is an even cleaner way to do this, by not copying props into state, but using props directly (implies parsing query params in render). Will update accordingly. |
I don't think we use query parameters in addition to the hash (yet). |
Correct. In React 16
According to these links, you are changing the query string: http://localhost:5000/#/file?revision=980d4dc65afc&path=mfbt/Assertions.cpp You can use the |
I think you meant "Use |
Yep, my mistake! |
Well, we still need to asynchronously fetch new data whenever revision or path change, so I still went with the |
@armenzg Please take another look. |
src/containers/fileViewer.jsx
Outdated
} | ||
// Reset the state and fetch new data | ||
this.setState({ | ||
coverage: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting anything in state to undefined
is synonymous with the field not being changed. You will want to set these to null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this line does successfully change state.coverage
to undefined
in the next render
call, properly displaying that this information is pending again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address the question, fix the linting issues (see Travis) and feel free to land if @eliperelman has no objections.
I wonder how linting issues could have been introduced with lint-staged and husky:
https://github.com/mozilla/firefox-code-coverage-frontend/blob/master/package.json#L20
src/containers/fileViewer.jsx
Outdated
coverage: undefined, | ||
parsedFile: undefined, | ||
}); | ||
this.setState(this.parseQueryParams()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we make two calls to setState()
instead of one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first call resets coverage
and parsedFile
(to clear old data), and the second call updates appError
, revision
and path
according to the new URL.
We could do both in one call, but that would imply hacking the object returned by this.parseQueryParams()
to add the two coverage: undefined
and parsedFile: undefined
entries, which would be even more verbose.
@eliperelman, please see my reply to your comment. Setting state entries to Please let me know if you feel very strongly about
That's my fault. I really hate commit hooks, because they totally break my flow (I want commit to happen instantly, even for WIP / temporary / experimental commits that may have lint issues) so my muscle memory now adds EDIT: And also, #194 makes linting perma-fail on my setup (because I use Node 10). |
@armenzg the two Travis failures are caused by the lint rule
However, the consensus seems to be that this is OK, as long as you wrap your |
From today on IRC: 15:41:03 ~Eli> janx: if armen is happy, ship it
STR
git clone https://github.com/mozilla/firefox-code-coverage-frontend/ front && cd front
yarn install && yarn start
Enter
Expected result
ChaosMode.cpp
Actual result
Cmd + R
to force a page reload and get the correct data)The fix
This pull request fixes this by resetting the state when getting a
'hashchange'
event.@armenzg please take a look.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)