Skip to content

update: adding a Wasm target to the full stack KMP tutorial #631

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

Merged
merged 9 commits into from
Jul 9, 2025

Conversation

zamulla
Copy link
Collaborator

@zamulla zamulla commented Jun 4, 2025

No description provided.

Copy link

coderabbitai bot commented Jun 4, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce support for the WebAssembly JavaScript target in the Kotlin Multiplatform project by updating dependencies and build configurations. New Compose UI implementations for the task manager app are added. The server is updated to support CORS, and documentation is revised for clarity and accuracy, with no changes to public code interfaces.

Changes

Files/Groups Change Summary
.../composeApp/build.gradle.kts
.../gradle/libs.versions.toml
Added Ktor client dependency for WebAssembly JS; added Ktor CORS server and wasm client libraries to the version catalog.
.../server/build.gradle.kts
.../server/src/main/.../Application.kt
Added Ktor CORS dependency and plugin installation for CORS support in the server application.
.../composeApp/src/commonMain/kotlin/.../App.kt Updated imports to fully qualified names; changed LazyColumn modifier to use safe content padding instead of fixed padding.
.../composeApp/src/commonMain/kotlin/.../App_first.kt Added new Compose UI component App to fetch and display tasks with a button.
.../composeApp/src/commonMain/kotlin/.../App_second.kt Added Compose UI with task fetching, display, and delete functionality; introduced TaskCard component.
.../composeApp/src/commonMain/kotlin/.../network/TaskApi.kt Added import for Task class to enable its usage in API methods.
topics/full-stack-development-with-kotlin-multiplatform.topic Editorial and instructional documentation updates for clarity, consistency, and accuracy; no code or API changes.

Suggested reviewers

  • Stexxe
  • osipxd

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@zamulla zamulla marked this pull request as ready for review June 13, 2025 16:48
@zamulla zamulla requested a review from vnikolova June 13, 2025 16:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🧹 Nitpick comments (1)
codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/App.kt (1)

60-63: Modifier order: call fillMaxSize() before safeContentPadding()

safeContentPadding() adds insets; placing it first means the column might not actually fill the full size in some layouts.

-LazyColumn(
-    modifier = Modifier
-        .safeContentPadding()
-        .fillMaxSize()
-) {
+LazyColumn(
+    modifier = Modifier
+        .fillMaxSize()
+        .safeContentPadding()
+) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67df109 and 0baf72c.

⛔ Files ignored due to path filters (3)
  • images/full_stack_development_tutorial_create_project.png is excluded by !**/*.png
  • images/full_stack_development_tutorial_run_android.png is excluded by !**/*.png
  • images/full_stack_development_tutorial_run_web.png is excluded by !**/*.png
📒 Files selected for processing (9)
  • codeSnippets/snippets/full-stack-task-manager/composeApp/build.gradle.kts (1 hunks)
  • codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/App.kt (2 hunks)
  • codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/App_first.kt (1 hunks)
  • codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/App_second.kt (1 hunks)
  • codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/network/TaskApi.kt (1 hunks)
  • codeSnippets/snippets/full-stack-task-manager/gradle/libs.versions.toml (1 hunks)
  • codeSnippets/snippets/full-stack-task-manager/server/build.gradle.kts (1 hunks)
  • codeSnippets/snippets/full-stack-task-manager/server/src/main/kotlin/com/example/ktor/full_stack_task_manager/Application.kt (2 hunks)
  • topics/full-stack-development-with-kotlin-multiplatform.topic (24 hunks)
🔇 Additional comments (3)
codeSnippets/snippets/full-stack-task-manager/gradle/libs.versions.toml (1)

41-41:

❌ Incorrect review comment

Potentially wrong artifact coordinates for WASM client

For Ktor 3.1.3 the published artifact is io.ktor:ktor-client-wasm-js (no extra js-wasm-js suffix).
If the coordinates are off, ./gradlew :composeApp:wasmJsMainDependenciesMetadata will fail with “Could not find …”.
Please double-check and adjust:

-ktor-client-wasm = { module = "io.ktor:ktor-client-js-wasm-js", version.ref = "ktor"}
+ktor-client-wasm = { module = "io.ktor:ktor-client-wasm-js", version.ref = "ktor" }

🏁 Script executed:

#!/usr/bin/env bash
echo "io.ktor:ktor-client-js-wasm-js 3.1.3:" $(curl -s "https://search.maven.org/solrsearch/select?q=g:io.ktor%20AND%20a:ktor-client-js-wasm-js%20AND%20v:3.1.3&rows=1&wt=json" | grep -Po '"numFound":\K\d+')
echo "io.ktor:ktor-client-wasm-js 3.1.3:"   $(curl -s "https://search.maven.org/solrsearch/select?q=g:io.ktor%20AND%20a:ktor-client-wasm-js%20AND%20v:3.1.3&rows=1&wt=json" | grep -Po '"numFound":\K\d+')

Length of output: 494


Artifact coordinates are correct as-is

The Maven Central lookup confirms that for Ktor 3.1.3 only io.ktor:ktor-client-js-wasm-js exists (numFound=1) while io.ktor:ktor-client-wasm-js does not (numFound=0). No change to libs.versions.toml is needed.

Likely an incorrect or invalid review comment.

codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/network/TaskApi.kt (1)

1-1: Import added – compilation issue resolved

Adding the Task import fixes the missing reference; no further issues spotted here.

topics/full-stack-development-with-kotlin-multiplatform.topic (1)

151-170: Doc-only change – looks fine
No technical concerns on the codebase side.

ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-serialization-kotlinx-json-jvm = { module = "io.ktor:ktor-serialization-kotlinx-json-jvm", version.ref = "ktor" }
ktor-server-content-negotiation-jvm = { module = "io.ktor:ktor-server-content-negotiation-jvm", version.ref = "ktor" }
ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor" }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Missing -jvm suffix breaks server build

Other server artefacts (e.g. ktor-server-core-jvm) carry the -jvm suffix; the CORS module follows the same pattern.
Using the suffix-less variant will resolve to the common (non-JVM) module and Netty will not see the CORS plugin at runtime.

-ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor" }
+ktor-server-cors = { module = "io.ktor:ktor-server-cors-jvm", version.ref = "ktor" }

🏁 Script executed:

#!/bin/bash
sed -n '30,60p' codeSnippets/snippets/full-stack-task-manager/gradle/libs.versions.toml

Length of output: 2828


🏁 Script executed:

#!/bin/bash
echo "### Checking availability of io.ktor:ktor-server-cors ###"
curl -s "https://search.maven.org/solrsearch/select?q=g:%22io.ktor%22+AND+a:%22ktor-server-cors%22&rows=5&wt=json" | jq '.response.docs[] | {id: .id, latestVersion: .latestVersion}'
echo
echo "### Checking availability of io.ktor:ktor-server-cors-jvm ###"
curl -s "https://search.maven.org/solrsearch/select?q=g:%22io.ktor%22+AND+a:%22ktor-server-cors-jvm%22&rows=5&wt=json" | jq '.response.docs[] | {id: .id, latestVersion: .latestVersion}'

Length of output: 775


Use the JVM-specific CORS module
The alias in libs.versions.toml currently points to the common (non-JVM) artifact, so the CORS plugin won’t load at runtime on your server. Update it to the JVM variant:

• Location:
codeSnippets/snippets/full-stack-task-manager/gradle/libs.versions.toml (around line 45)
• Change needed:

-ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor" }
+ktor-server-cors = { module = "io.ktor:ktor-server-cors-jvm", version.ref = "ktor" }

Other server modules (core, netty, content-negotiation, test-host) use the -jvm suffix—CORS should match.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor" }
ktor-server-cors = { module = "io.ktor:ktor-server-cors-jvm", version.ref = "ktor" }
🤖 Prompt for AI Agents
In codeSnippets/snippets/full-stack-task-manager/gradle/libs.versions.toml at
line 45, the ktor-server-cors module is referenced without the required -jvm
suffix, causing the server to load the common non-JVM artifact and fail to
recognize the CORS plugin at runtime. To fix this, update the module reference
from "io.ktor:ktor-server-cors" to "io.ktor:ktor-server-cors-jvm" so it matches
the JVM-specific suffix used by other server modules.

Comment on lines +20 to +24
val httpClient = createHttpClient()
val taskApi = remember { TaskApi(httpClient) }
val tasks = remember { mutableStateOf(emptyList<Task>()) }
val scope = rememberCoroutineScope()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Prevent heavy HttpClient re-creation on every recomposition

createHttpClient() is called on each recomposition, leaking connections and wasting resources.

-        val httpClient = createHttpClient()
+        val httpClient = remember { createHttpClient() }

Add cleanup to avoid leaking resources:

DisposableEffect(Unit) {
    onDispose { httpClient.close() }
}
🤖 Prompt for AI Agents
In
codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/App_first.kt
around lines 20 to 24, the HttpClient is recreated on every recomposition
causing resource leaks. To fix this, wrap the HttpClient creation in a
DisposableEffect with Unit as the key and call httpClient.close() inside
onDispose to properly clean up resources when the composable leaves the
composition.

Comment on lines +33 to +37
val httpClient = createHttpClient()
val taskApi = remember { TaskApi(httpClient) }
var tasks by remember { mutableStateOf(emptyList<Task>()) }
val scope = rememberCoroutineScope()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reuse a single HttpClient instance

Move creation into remember {} and dispose it on exit as shown for App_first.kt. This greatly reduces socket churn.

🤖 Prompt for AI Agents
In
codeSnippets/snippets/full-stack-task-manager/composeApp/src/commonMain/kotlin/com/example/ktor/full_stack_task_manager/App_second.kt
around lines 33 to 37, the HttpClient is created directly each time, causing
unnecessary socket churn. To fix this, wrap the HttpClient creation inside a
remember { } block to ensure a single instance is reused across recompositions,
and add proper disposal of the client when the composable exits, similar to the
pattern used in App_first.kt.

@zamulla zamulla changed the base branch from main to 3.2.1 July 8, 2025 11:50
Co-authored-by:  Vik Nikolova <[email protected]>
@zamulla zamulla requested a review from vnikolova July 9, 2025 16:11
@vnikolova vnikolova changed the base branch from 3.2.1 to main July 9, 2025 18:07
@vnikolova vnikolova merged commit a5988bb into main Jul 9, 2025
1 check passed
@vnikolova vnikolova deleted the full-stack-with-web branch July 9, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants