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

[WIP] Support React Refresh #1069

Draft
wants to merge 73 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
419509d
Add `testEmissions` module with ReactRefresh JS test
japgolly Jun 1, 2022
67f0713
Add EmissionTest
japgolly Jun 1, 2022
7d5f589
Merge branch 'master' into topic/refreshReact
japgolly Jun 1, 2022
f0e130f
Update emissions for SJS 1.10
japgolly Jun 1, 2022
9f484dc
Separate emission expectations by Scala version
japgolly Jun 1, 2022
3d057f8
Emissions output: replace unicode "_", add trailing line
japgolly Jun 1, 2022
5796d2e
Tweak EmissionTest conditions to showResult
japgolly Jun 2, 2022
1717979
Finally get working macros in place for a render hook method
japgolly Jun 2, 2022
89ee1f2
Remove useless line
japgolly Jun 6, 2022
8197dd3
Checkpoint: UseState on Scala 2
japgolly Jun 6, 2022
d3b8a09
HookDefn propsType not needed
japgolly Jun 6, 2022
39ce3dc
Handle `useStateBy` and `withPropsChildren`
japgolly Jun 6, 2022
bee7150
Fix formatting
japgolly Jun 6, 2022
ff104a4
Add TODO
japgolly Jun 6, 2022
008744e
Remove NoHooksWithChildren for now
japgolly Jun 6, 2022
d2e6f64
Fix and harden ReactRefreshTest
japgolly Jun 6, 2022
656a963
Rewrite `useStateWithReuse{,By}`
japgolly Jun 6, 2022
cfb090c
Create AbstractHookMacros
japgolly Jun 7, 2022
2005e88
Add `tcc` sbt alias
japgolly Jun 8, 2022
9967f39
Prepare `AbstractHookMacros` for Scala 3
japgolly Jun 8, 2022
1dda343
Let's try an external `HookRewriterCtx`
japgolly Jun 8, 2022
b9ccc8b
Refactor `HookRewriter` so that `ValDef` creation is atomic
japgolly Jun 9, 2022
d763377
Rename `tec` alias
japgolly Jun 9, 2022
c69eaf1
Further prep for Scala 3 support
japgolly Jun 9, 2022
e3c8da8
Scala 3 rewriting acting like its working
japgolly Jun 9, 2022
3bc3af9
Silence macrotasks warnings in downstream-tests
japgolly Jun 9, 2022
9425f16
Make SNAPSHOT versions stable
japgolly Jun 9, 2022
fd38f4b
Give up trying to preserve bincompat
japgolly Jun 10, 2022
11f0cf5
Revert "Give up trying to preserve bincompat"
japgolly Jun 10, 2022
02b1f18
Recover bincompat, turns out there was a node version issue
japgolly Jun 10, 2022
76790d5
Generate test emissions with less SJS safety
japgolly Jun 10, 2022
48f92cf
Make emission testing output more useful for debugging
japgolly Jun 10, 2022
84d6666
Add `renderDebug`
japgolly Jun 10, 2022
386f6a7
Turn rewrite failures into compiler warnings
japgolly Jun 10, 2022
13b9041
Support function refs in rewrite args
japgolly Jun 10, 2022
f0f87f9
Validate react-refresh version
japgolly Jun 13, 2022
3a75383
Upgrade to react-refresh 0.13.0
japgolly Jun 13, 2022
065ddb3
Support `custom*` hook methods
japgolly Jun 13, 2022
2f1851c
Properly handle intermediary hooks with Unit results
japgolly Jun 14, 2022
b28aac6
Refactor and improve readability of new hook macro code
japgolly Jun 14, 2022
725a7fd
Improve ReactRefreshTest
japgolly Jun 14, 2022
1128fc4
Add emission tests for custom hooks
japgolly Jun 14, 2022
7275c97
Upgrade react-refresh to 0.14.0 (identical to 0.13.0 anyway)
japgolly Jun 16, 2022
1a13dfe
Oh no, custom hooks need rewriting too
japgolly Jun 16, 2022
931a8d3
Gonna have to add `renderRR` and leave `render` alone
japgolly Jun 16, 2022
cbdd990
Test hook components with `.render` and with `.renderRR`
japgolly Jun 16, 2022
19a50aa
Reorder methods in HookMacros
japgolly Jun 16, 2022
073ee30
Refactor: rename secondary render macro methods
japgolly Jun 16, 2022
faac76e
Fix rewriting of custom hooks with local vals in Scala 3
japgolly Jun 16, 2022
6f16bcb
Make `Hook{Defn,Step}` static
japgolly Jun 16, 2022
729ef6d
Support RR on the hooks primary API
japgolly Jun 17, 2022
70cde24
Refactor for readability
japgolly Jun 17, 2022
d0e4ea6
Support and test, all variations of hook component creation with RR
japgolly Jun 17, 2022
c07533a
Support rewriting of `local*` and `unchecked*` hooks
japgolly Jun 20, 2022
de5e001
Tiny tweak - too tired to actually describe
japgolly Jun 20, 2022
f2c63de
Inline `HookCtx` stuff
japgolly Jun 20, 2022
63a2045
Got `useCallback` working
japgolly Jun 21, 2022
8298460
Rename last context object to `render_ctx`
japgolly Jun 21, 2022
55723b7
Support `useCallbackWithDeps*`
japgolly Jun 21, 2022
6d66364
`useMemo*` done
japgolly Jun 22, 2022
142f6e1
`use{Context,DebugValue,Reducer}` done
japgolly Jun 22, 2022
2fb130a
Avoid shadowing in Scala 2
japgolly Jun 22, 2022
e868482
Consolidate some RR tests; test time is starting to get annoying
japgolly Jun 22, 2022
5c17b04
`use*Effect*`
japgolly Jun 23, 2022
63c5df6
`useForceUpdate` take 2
japgolly Jun 23, 2022
a8693f4
Support `useRef*`
japgolly Jun 24, 2022
df81d84
Remove obsolete emission test output
japgolly Jun 27, 2022
17f5b09
Upgrade Scala.js and re-gen all emissions
japgolly Jun 27, 2022
fc559e0
Support render with reuse with children
japgolly Jun 27, 2022
c4cf1b3
Fix Scala 2 compilation - stategy is fine
japgolly Jun 27, 2022
ebfd757
Re-generate all test emissions with Scala.js 1.10.1
japgolly Jun 28, 2022
ad7b116
Add placeholder implementations for renderRR with reuse
japgolly Jun 27, 2022
3a428e3
Support RR in `render{Reusable,WithReuse,WithReuseBy}`
japgolly Jun 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ fi

case "${1:-}" in
"")
"$0" 2
../bin/"$0" 2
echo
echo
"$0" 3
../bin/"$0" 3
exit 0
;;
2|3)
Expand All @@ -40,6 +40,7 @@ echo
rm -rf */target/scala-*/{,test-}classes
cmd=(
sbt
-DCI=1
-J-Xmx3G
-J-XX:+UseG1GC
++$SCALA_VER
Expand Down
39 changes: 39 additions & 0 deletions bin/mima
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")/../library"

if [ $# -gt 1 ]; then
echo "Usage: $0 [<scala ver>]"
echo ""
echo "Where"
echo " <scala ver> = 2 or 3"
echo
exit 1
fi

case "${1:-}" in
"")
../bin/"$0" 2
echo
echo
../bin/"$0" 3
exit 0
;;
2|3)
SCALA_VER="$(../bin/get_scala_version $1)"
echo "Scala version: $SCALA_VER"
;;
*)
echo "Unrecognised version: $1" >&2
exit 2
;;
esac

# Test upstream
# rm -rf */target/scala-*/{,test-}classes
sbt ++$SCALA_VER publishLocal

# Test downstream
SCALA_MAJOR_VER="${SCALA_VER:0:1}"
cd ../downstream-tests
sbt ++$SCALA_VER mima200/clean mima200/fastOptJS
5 changes: 3 additions & 2 deletions downstream-tests/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ def scalacCommonFlags: Seq[String] = Seq(
"-language:higherKinds",
"-language:existentials",
"-unchecked",
"-Wconf:msg=may.not.be.exhaustive:e", // Make non-exhaustive matches errors instead of warnings
"-Wconf:msg=Reference.to.uninitialized.value:e", // Make uninitialised value calls errors instead of warnings
"-Wconf:msg=macrotask:s", // stfu about macrotasks
)

def scalac2Flags = Seq(
"-Wconf:msg=may.not.be.exhaustive:e", // Make non-exhaustive matches errors instead of warnings
"-Wconf:msg=Reference.to.uninitialized.value:e", // Make uninitialised value calls errors instead of warnings
"-Wunused:explicits", // Warn if an explicit parameter is unused.
"-Wunused:implicits", // Warn if an implicit parameter is unused.
"-Wunused:imports", // Warn if an import selector is not referenced.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package downstream.mima200

import japgolly.scalajs.react._
import japgolly.scalajs.react.vdom.html_<^._

// Because in `object Hooks.UseReducer`, I changed `private def _unsafeCreate` to `def fromJs`
object HookUseReducer {

final case class PI(pi: Int) {
def unary_- : PI = PI(-pi)
def *(n: Int): PI = PI(pi * n)
def +(n: Int): PI = PI(pi + n)
def +(n: PI): PI = PI(pi + n.pi)
}

private def add(n: Int): (Int, Int) => Int = _ + _ + n

val comp = ScalaFnComponent.withHooks[PI]
.useReducer(add(0), 100)
.useReducerBy((_, s1) => add(s1.value), (p, s1) => p.pi + s1.value)
.useReducerBy($ => add($.hook1.value), $ => $.props.pi + $.hook1.value + $.hook2.value)
.render((p, s1, s2, s3) =>
<.div(
<.div(s"P=$p, s1=${s1.value}, s2=${s2.value}, s3=${s3.value}"),
<.button(^.onClick --> s1.dispatch(1)),
<.button(^.onClick --> s2.dispatch(10)),
<.button(^.onClick --> s3.dispatch(100)),
))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package downstream.mima200

import japgolly.scalajs.react._
import japgolly.scalajs.react.vdom.html_<^._

// Because `useRefToJsComponent` didn't need the `CT0` arg so I removed it.
object HookUseRefToJsComponent {

val jsComp = JsComponent.force[Null, Children.None, Null](null)

val comp = ScalaFnComponent.withHooks[Unit]
.useRefToJsComponent(jsComp)
.render { (_, ref) =>
jsComp.withRef(ref)()
}
}
1 change: 1 addition & 0 deletions downstream-tests/version.sbt
31 changes: 20 additions & 11 deletions library/aliases.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
addCommandAlias("CB", "project coreBundleCallback")
addCommandAlias("CE", "project coreBundleCatsEffect")
addCommandAlias("CG", "project coreGeneric")
addCommandAlias("E", "project extra")
addCommandAlias("FM", "project facadeMain")
addCommandAlias("FT", "project facadeTest")
addCommandAlias("GH", "project ghpages")
addCommandAlias("M2", "project extraExtMonocle2")
addCommandAlias("M3", "project extraExtMonocle3")
addCommandAlias("TS", "project tests")
addCommandAlias("TU", "project testUtil")
addCommandAlias("CB", "project coreBundleCallback")
addCommandAlias("CE", "project coreBundleCatsEffect")
addCommandAlias("CG", "project coreGeneric")
addCommandAlias("E", "project extra")
addCommandAlias("FM", "project facadeMain")
addCommandAlias("FT", "project facadeTest")
addCommandAlias("GH", "project ghpages")
addCommandAlias("M2", "project extraExtMonocle2")
addCommandAlias("M3", "project extraExtMonocle3")
addCommandAlias("TE", "project testEmissions")
addCommandAlias("TEJ", "project testEmissionsJS")
addCommandAlias("TT", "project tests")
addCommandAlias("TU", "project testUtil")

addCommandAlias("tcc", "compile; Test/clean; Test/compile")
addCommandAlias("tt", "tests/test")
addCommandAlias("th", "coreGeneric/compile; tests/testOnly *Hook*")
addCommandAlias("thc", "coreGeneric/compile; tests/Test/clean; tests/testOnly *Hook*")
addCommandAlias("te", "testEmissions/test")
addCommandAlias("tec", "testEmissionsJS/clean;testEmissions/test")
8 changes: 8 additions & 0 deletions library/bin/remove_test_emissions
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd "$(dirname "$0")/.." || exit 1
[ $# -ne 1 ] && echo "Usage: $0 <scala major-version>" && exit 1

set -euo pipefail

rm -fv ./testEmissions/jvm/src/test/resources/rr-sjr/*-out"$1".js
4 changes: 3 additions & 1 deletion library/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ val ghpages = ScalaJsReact.ghpages
val ghpagesMacros = ScalaJsReact.ghpagesMacros
val root = ScalaJsReact.root
val scalafixRules = ScalaJsReact.scalafixRules
val testEmissions = ScalaJsReact.testEmissions
val testEmissionsJS = ScalaJsReact.testEmissionsJS
val tests = ScalaJsReact.tests
val testUtilMacros = ScalaJsReact.testUtilMacros
val testUtil = ScalaJsReact.testUtil
val testUtilMacros = ScalaJsReact.testUtilMacros
val util = ScalaJsReact.util
val utilCatsEffect = ScalaJsReact.utilCatsEffect
val utilDummyDefaults = ScalaJsReact.utilDummyDefaults
Expand Down
Loading