This repository has been archived by the owner on Dec 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Code review #4
Labels
enhancement
New feature or request
Comments
This was referenced Jan 21, 2019
Merged
This PR #6 should resolve the following:
@thibaudcolas would be good to get you to confirm and provide your thoughts :) |
Sweet, I'll try to have a look this weekend! |
Thank you very much to both of you for these contributions! @thibaudcolas I improved a lot of things as well after @jonnyscholes’ contribution. I leave this review open for me to fix the remaining unticked checkboxes. But for now, this is already more than good to be in Wagtail :) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Alright! 🙂 I generally don't have the chance to review a whole package, that was a lot of fun. In the end I tried to be as exhaustive as possible with my comments, but a lot of it is fairly minor / quick to address.
I made the review as a pull request that contains all of the package's code, over at thibaudcolas#1, so it would be easier to relate comments to code. But I also summarised most of the comments below, so they are easier to relate to one another, and prioritise. It's probably easier to first read this list, then the comments in the PR.
I also made a PR to address some of the issues below (packaging, dev tools, and API), over at #5, along with the corresponding changes to Wagtail in a branch that builds upon wagtail/wagtail#4942.
Potential problems
These are the code-level problems I would expect to cause the most pain / actual bugs. They are ordered by how important I think they are to address sooner rather than later.
icon
,field
,required
) – these should use BEM, and-or be namespaced (see "Styles" section below, and Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))aside
,article
,header
. They provide no semantic value for a form / widget like StreamField (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))AddButton
'sgroupedBlockDefinitions
– What happens if key is an empty string? It seems like this is going to override the groups (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))extractText
– Use eithertextContent
orinnerText
depending on the desired outcome (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))CustomEvent
polyfill to Wagtail for IE11 support, or change the code not to need it (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))initEvent
with event constructor (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))StreamField
constructor side-effects tocomponentDidMount
(see react-redux section below) (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Performance
Revisit the AnimateHeight implementations to only render their children to the DOM when they are meant to be displayed (AddButton's panel, Block children) (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))componentDidMount
, which can cause memory leaks (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Error handling
Generally I haven't seen much error handling code. I would expect the inner script execution to be the most problematic, since it will be very common for third-party code to break.
componentDidMount
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))moveBlock
action (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))componentDidCatch
?) for unforeseen sources of errorMinor ones
Minor but still sources of concern
Preserve script tags in inner script execution instead of usingeval
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))<BlocksContainer />
isn't valid HTML. We shouldn't encourage people to write HTML that doesn't pass validation. For a semantic-free token/placeholder, use anoscript
tag with a data attribute. (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))getIsMobile
– Usewindow.matchMedia
to make sure the JS and CSS breakpoint definitions are in sync (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Packaging - build & dependenceies
The general problem here is that the library is compiled as if it was an app, instead of a library, with all of its dependencies bundled instead of resolved by npm on install.
main
andmodule
attributes inpackage.json
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))"sideEffects": false,
for Webpack consumers (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))dist
) via npm only, not in version control (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))package.json
. Instead, use apackage-lock.json
. (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))dependencies
:classnames
,react-animate-height
,react-beautiful-dnd
,uuid
(react-redux
,redux
,redux-thunk
,react
,react-dom
,prop-types
) (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))peerDependencies
:react-redux
,redux
,redux-thunk
,react
,react-dom
,prop-types
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Bonus points
sass
(official Dart implementation) to get rid of the annoying native code compilation ofnode-sass
. (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))transform-react-remove-prop-types
to wrap proptypes instead of removing them, as for a project like this they can be very useful in dev mode. (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))@babel/cli
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))@babel/plugin-proposal-decorators
and decorators syntax with normal higher-order functions/components. (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Documentation
To me this is what would be the most worthy of documentation. The
blockDefinitions
schema is probably this package’s most important API, and the polyfills are its least obvious requirements.blockDefinitions
schema (can be as simple as adding comments toBlockDefinitionType
, and linking to this) (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))position: sticky
polyfill in the project's README, and in https://docs.wagtail.io/en/v2.4/contributing/developing.html?highlight=Sticky (Wagtail doesn't come with one, it's very expensive perf-wise), for full IE11 support (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))element-closest
polyfill for IE11 support (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Array#find
polyfill for IE11 support (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Object#entries
polyfill for IE11 support (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))CustomEvent
polyfill for IE11 support (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Development & demo env
drop_console
setting from UglifyJS setup (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Styles
src/index.scss
into multiple files, ideally following the separation between React components (one styles file per component) (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment)).add-block-button
instead ofbutton.add
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment)).children-container--dragging
instead of.children-container.is-dragging
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment)).block-header
instead ofheader
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Consider using a JS-added--focus
class instead of:focus-within
, if the functionality is important enough (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Accessibility
I'm sure the current StreamField implementation isn't particularly SR-friendly, so we're not aiming super high, but there are obvious improvements to be made here.
AddButton
’s + icon should have a text-only label for screen reader users (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))aria-hidden="true"
so screen readers ignore them (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))react-redux
react-redux recently released its v6, which uses the new React context API from React 16.4, and introduces a change in behavior that affects this package:
This is the problematic code:
https://github.com/noripyt/react-streamfield/blob/9b720dd715140f5c931560e75431ea472600f9be/src/StreamField.js#L95-L107
The consequence is that
BlocksContainer
will fail to render because it does not expect to have access to an uninitialised state. It's generally not recommended to have side-effects in the constructor anyway, moving this init tocomponentDidMount
would make the problem even more obvious.I can see a few solutions:
initializeStreamField
logic out ofStreamField
, to be done when the store is createdinitializeStreamField
call tocomponentDidMount
, and do not render theBlockContainer
until initialisation is over.Anyway, it's not necessary to upgrade to v6 now. I also have two concerns with the upgrade:
peerDependencies
. Using different versions from it would mean they get bundled twice for end users, which I would rather avoid. From memory Redux is fairly small in size, butreact-redux
is a good 20kb.Finally on the react-redux front, I'm surprised that all/most of the components in the package are connected. I would expect the performance to be better if some of the connections were removed, as they clearly duplicate their computation (but use
PureComponent
orReact.memo
to still have the same rendering performance)BlockContent
, and use props fromBlock
instead (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))BlockHeader
, and use props fromBlock
instead (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))BlockActions
, and use props fromBlock
instead (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))RawHtmlFieldInput
, and use props fromFieldInput
instead (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))This would also make it easier to write tests for those components, which I would really like to see.
Smaller JS / React things
setState
calls such asthis.setState({open: !this.state.open});
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))addHandler
's key to the function, instead of storing it and reading it in HTML. (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))if (value)
instead ofif (value === null)
,value !== undefined
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment), Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))<></>
) (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))Remove unneeded boolean parameter ofgetDescendantsIds
(always called withtrue
) (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))getNewBlock
of the utils into smaller functions (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))MutationObserver
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))h3
for BlockHeader's icon (Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))actions.js
toreducers.js
(Code review for upcoming Wagtail integration thibaudcolas/react-streamfield#1 (comment))The text was updated successfully, but these errors were encountered: