Repository navigation
Add compiler lowering for Compose HTML EAP SSR - #5769
Clemens Koprolin (clemenskoprolin) wants to merge 1 commit into
Conversation
Prepare static HTML and attributes at compile time, lower supported elements to direct writer calls and provide a Gradle plugin with JVM and browser integration coverage.
|
|
||
| val sharedSerializationSources = tasks.register<Sync>("syncSerializationSources") { | ||
| from("../core/src/commonMain/kotlin") { | ||
| include("org/jetbrains/compose/web/dom/HtmlSerializationRules.kt") |
There was a problem hiding this comment.
When editing those files, it's not obvious that they are used here in the compiler plugin implementation.
What do you think about extracting html-serialization-related helpers into a separate module and adding it as a usual dependency here?
The problem is that most of the helpers are "internal" and ideally they remain "internal". But for our needs it's fine to suppress the usages.
| * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
| */ | ||
|
|
||
| pluginManagement { |
There was a problem hiding this comment.
Could the compiler plugin be included directly in the root settings?
Any reason why it's a standalone gradle project?
| * | ||
| * @Composable | ||
| * fun UserName(name: @Composable () -> String) { | ||
| * PreparedTextElement(__htmlAttributes0) { |
There was a problem hiding this comment.
Why not write directly to HtmlStringWriterContext ? Why is the field necessary?
| * } | ||
| * ``` | ||
| */ | ||
| abstract class HtmlLoweringExtension { |
There was a problem hiding this comment.
Let's keep just one property?
val enabledTargets: SetProperty< KotlinPlatformType>
With Jvm enabled by default
| assertEquals( | ||
| "<span id=\"greeting\" title=\""<&> 	😀\"" + | ||
| " data-key=\"value\" class=\"label accent last\">text</span>", | ||
| composeHtmlToString { |
There was a problem hiding this comment.
As I see, this and some other tests pass even when the compiler plugin is disabled.
After this PR, I think it's worth to implement tests comparing the generated IR with the golden one.
Here is an example from Compose compiler plugin tests - https://github.com/JetBrains/kotlin/blob/de4aa1dfb1546fc83006f5833c5dce24948ebfc3/plugins/compose/compiler-hosted/integration-tests/testResources/golden/androidx.compose.compiler.plugins.kotlin.ClassStabilityTransformTests/testComposableCall.txt
Seeing such IR golden snippets help understand what the compiler plugin is supposed to do in every case.
| } | ||
|
|
||
| internal inline fun forEachRenderMode(test: (strict: Boolean, hydratable: Boolean, stream: Boolean) -> Unit) { | ||
| for (strict in listOf(false, true)) for (hydratable in listOf(false, true)) for (stream in listOf(false, true)) { |
There was a problem hiding this comment.
Could you please reformat the files in this PR?
https://www.jetbrains.com/help/idea/reformat-and-rearrange-code.html#reformat_file (Cmd+option+shift+L)
It won't reformat these nested loops, so to make it more readable could you please format it manually?
internal inline fun forEachRenderMode(test: (strict: Boolean, hydratable: Boolean, stream: Boolean) -> Unit) {
val variants = listOf(false, true)
for (strict in variants) {
for (hydratable in variants) {
for (stream in variants) {
test(strict, hydratable, stream)
}
}
}
}
Perhaps in other places too.
Introduces a JVM compiler plugin that prepares static HTML at compile time and replaces supported composables with direct writer calls. Dynamic values remain escaped at runtime, unsupported calls retain normal rendering.
E.g.:
Becomes the equivalent of:
With dynamic text instead:
it becomes equivalent of:
Supported lowering includes:
repeatbodies → precomputed HTML literals.TagElementcalls and custom wrappers annotated with@LowerableHtmlTag→ optimized writer calls where supported.Includes a Gradle plugin, shared serialization rules and JVM bytecode and browser hydration tests. Prepared static HTML can retain text-boundary comments when
hydratable = false.Involves CMP-10991 and CMP-10836
Testing
Run from the
htmldirectory:Release Notes
N/A