Coder Social home page Coder Social logo

wagtail-deprecated / react-streamfield Goto Github PK

View Code? Open in Web Editor NEW
34.0 20.0 12.0 4.12 MB

Powerful field for inserting multiple blocks with nesting. (NO LONGER MAINTAINED - See Wagtail 2.13 Release Notes)

Home Page: https://wagtail.github.io/react-streamfield/public/

HTML 57.56% JavaScript 40.38% SCSS 2.06%
react streamfield field wagtail

react-streamfield's Introduction

⚠️ No longer maintained: Features have been merged into Wagtail see 2.13 Release Notes.

React StreamField npm Build Status

Powerful field for inserting multiple blocks with nesting.

Originally created for the Wagtail CMS thanks to a Kickstarter campaign.

React StreamField screenshot

Demo

https://wagtail.github.io/react-streamfield/public/

Example usage

To have an idea on how to fully integrate react-streamfield, please check this CodeSandbox demo.

For more complex examples, see example/index.story.js and the corresponding demos for more complex examples.

More documentation will arrive soon!

You can also check out wagtail-react-streamfield to see what an integration of this field looks like!

Internet Explorer 11 support

These JavaScript features are used in react-streamfield that are not supported natively in Internet Explorer 11:

  • Element.closest(…)
  • Array.find(…)
  • Object.entries(…)
  • CustomEvent

When using react-streamfield for Internet Explorer 11, you need to include the polyfills found in the section below, otherwise the package will not work properly.

Polyfills

React-streamfield uses some JavaScript features only available starting ECMAScript 2015. Some of these features are not handled by browsers such as Internet Explorer 11.

To maintain compatibility when using react-streamfield, install and import these polyfills (a polyfill adds a missing JavaScript browser feature):

{
  "dependencies": {
    "core-js": "^2.6.5",
    "element-closest": "^3.0.1",
    "custom-event-polyfill": "^1.0.6"
  }
}
import 'core-js/shim'
import 'element-closest';
import 'custom-event-polyfill';

Webpack stats

https://wagtail.github.io/react-streamfield/public/webpack-stats.html

react-streamfield's People

Contributors

bertrandbordage avatar jonnyscholes avatar lb- avatar siimonevans avatar thibaudcolas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-streamfield's Issues

Code review

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.

Performance

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.

Minor ones

Minor but still sources of concern


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.

Bonus points

  • Consider using sass (official Dart implementation) to get rid of the annoying native code compilation of node-sass. (thibaudcolas#1 (comment))
  • Consider configuring 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. (thibaudcolas#1 (comment))
  • Remove unused @babel/cli (thibaudcolas#1 (comment))
  • Consider replacing @babel/plugin-proposal-decorators and decorators syntax with normal higher-order functions/components. (thibaudcolas#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.

Development & demo env

Styles

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.

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:

[...] there is a behavior change around dispatching actions in constructors / componentWillMount. Previously, dispatching in a parent component's constructor would cause its children to immediately use the updated state as they mounted, because each component read from the store individually. In version 6, all components read the same current store state value from context, which means the tree will be consistent and not have "tearing". This is an improvement overall, but there may be applications that relied on the existing behavior.

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 to componentDidMount would make the problem even more obvious.

I can see a few solutions:

  • Move the initializeStreamField logic out of StreamField, to be done when the store is created
  • Move initializeStreamField call to componentDidMount, and do not render the BlockContainer until initialisation is over.

Anyway, it's not necessary to upgrade to v6 now. I also have two concerns with the upgrade:

  • react-beautiful-dnd also uses Redux and react-redux v5, but doesn't declare them as 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, but react-redux is a good 20kb.
  • Wagtail uses v5, and switching to v6 will require updating Wagtail's code. Shouldn't be a big deal, but it will take a bit of time.

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 or React.memo to still have the same rendering performance)

This would also make it easier to write tests for those components, which I would really like to see.

Smaller JS / React things

Helping out with the react-streamfield

Hi @BertrandBordage,

We are extending the react-streamfield on https://github.com/stamkracht/react-streamfield. Already did some minor updates that gives us a bit more control through the blockDefinitions. We are manipulating the blockDefinition through get_definition so we didn't need todo any Python changes yet.

I've seen the RFC and a lot of it is stuff we can also use and I wonder if we can help you achieving those features? We have a lot of in-house experience with both Python and JS. It would be a shame if we do the same stuff but slightly different, so maybe you can give your thoughts on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.