-
The
.getDOMNode
callback can sometimes execute when unmounted which is an increasingly annoying bug to track down. Since React 16 with its new burn-it-all-down error handling approach, an occurance of this can be fatal (and caused my entire app to just suddenly unmount in disappear in the middle of a demo).
This release adjusts the types to restore compile-time safety. Unfortunately it's a breaking change. There is now a proper ADT:ComponentDom ↑ ↑ ComponentDom.Mounted ComponentDom.Unmounted ↑ ↑ ComponentDom.Element ComponentDom.Text
Calling
.getDOMNode
from without lifecycle callbacks, returns aComponentDom.Mounted
, logically equivalent to before. Calling.getDOMNode
on a mounted component instance or aBackendScope
now returnsComponentDom
which may or may not be mounted. Jump into theComponentDom
source to see the available methods but in most cases you'll use one of the following:trait ComponentDom { def mounted : Option[ComponentDom.Mounted] def toElement: Option[dom.Element] def toText : Option[dom.Text]
In unit tests you'll typically use
asMounted().asElement()
orasMounted().asText()
for inspection. -
React 16.3 support
- New component lifecycle:
getDerivedStateFromProps
- New component lifecycle:
getSnapshotBeforeUpdate
There is compile-time enforcement of some rules aroundgetSnapshotBeforeUpdate
which you'll find out about at compile-time (in an informative way) if you violate; you can also read about it and how it was implemented here: https://japgolly.blogspot.com/2018/07/enforcing-rules-at-compile-time-example.html - React Context API implemented via
React.createContext
andReact.Context
. - React ref forwarding
- Forward a ref via
React.forwardRef
- Wrap a JS ref-forwarding component via
JsForwardRefComponent
- Refs are now based on
React.createRef()
- Components now have
.withRef
functions just like VDOM - docs & example
- Forward a ref via
- Add
React.StrictMode
- New component lifecycle:
-
React 16.4 support
- Add new types:
ReactPointerEvent
ReactPointerEventFrom[N]
ReactPointerEventFromHtml
ReactPointerEventFromInput
ReactPointerEventFromTextArea
- Add new events to the vdom and for tests, event simulation:
onGotPointerCapture
onLostPointerCapture
onPointerCancel
onPointerDown
onPointerEnter
onPointerLeave
onPointerMove
onPointerOut
onPointerOver
onPointerUp
- Add new types:
-
React 16.5 support
- New event:
onAuxClick
- New mouse event attributes:
movementX
andmovementY
- New pointer event attributes:
tangentialPressure
andtwist
- New event:
-
Adding support for React 16.3's new
getSnapshotBeforeUpdate
lifecycle callback was quite disruptive and resulted in the following knock-on changes:-
.configure
inScalaComponent.builder
now only accepts one argument. -
ScalaComponent.Config
(used for externalising and reusing opaque component lifecycle logic) has changed from a bearabletype Config[P, C <: Children, S, B]
to the horrendous definition below. It's not something that many people use and even when they do it's infrequent, but hopefully a workaround can be found soon anyway./** This is terrible and repulsive but Scala doesn't allow anything less repulsive. * We'll keep this correctly modelling the reality for now and soon see if maybe we can use macros to * simplify it's creation (and avoid the need to use this explicitly). */ type Config[P, C <: Children, S, B, US <: UpdateSnapshot, US2 <: UpdateSnapshot]
-
LogLifecycle
has been deleted without replacement
-
-
Added to
ScalaComponent.builder
:.configureWhen
and.configureUnless
-
Deprecated
ReactFragment
and replaced withReact.Fragment
-
Add
setRequestHeader
to Ajax -
Trying to treat a JS Symbol as a React component now provides a meaningful error message
-
Add
cloneElement(…)
to React JS facade -
Add to
japgolly.scalajs.react.test.SimEvent.{Mouse,Pointer}
def simulateClick
anddef simulationClick
def simulateContextMenu
anddef simulationContextMenu
def simulateDoubleClick
anddef simulationDoubleClick
-
New HTML attributes
noModule
playsInline
-
New SVG attribute:
focusable
-
ScalaFnComponent
s that have a Props type ofUnit
are now invoked asBlah()
instead ofBlah(())
-
Deprecate
asEventDefault
in theobject CallbackOption
and move it to theclass CallbackOption
-
Add
asEventDefault
toCallback(To)
-
Update dependencies:
- Cats to 1.4.0
- Scalaz to 7.2.26
- Scala.JS to 0.6.25
find . -name '*.scala' -type f -exec perl -pi -e '
s/ReactFragment/React.Fragment/g;
' {} +
find . -path '*/test/scala/*.scala' -type f -exec perl -pi -e '
s/getDOMNode.asElement/getDOMNode.asMounted().asElement()/g;
s/getDOMNode.asText/getDOMNode.asMounted().asText()/g;
s/getDOMNode.domCast/getDOMNode.asMounted().domCast/g;
' {} +
If you like what I do —my OSS libraries, my contributions to other OSS libs, my programming blog— and you'd like to support me, more content, more lib maintenance, please become a patron! I do all my OSS work unpaid so showing your support will make a big difference.