Skip to content

Commit 4f50d54

Browse files
committed
Isolate SSR operations with fresh PlatformRenderer instances
Always creating a new `PlatformRenderer` ensures better state isolation across server-side rendering calls. This prevents potential state pollution from previous operations and improves rendering reliability.
1 parent 004aad6 commit 4f50d54

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

summon-core/src/commonMain/kotlin/codes/yousef/summon/ssr/ServerSideRendering.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package codes.yousef.summon.ssr
22

33
import codes.yousef.summon.annotation.Composable
4-
import codes.yousef.summon.runtime.getPlatformRenderer
54
import kotlinx.coroutines.flow.Flow
65

76
/**
@@ -403,13 +402,10 @@ object ServerSideRenderUtils {
403402

404403
val context = RenderContext(initialState = initialData, enableHydration = includeHydrationScript)
405404

406-
// Get the platform renderer (create one if needed)
407-
val platformRenderer = try {
408-
getPlatformRenderer()
409-
} catch (e: Exception) {
410-
// If no renderer is set, create a new one
411-
codes.yousef.summon.runtime.PlatformRenderer()
412-
}
405+
// Always create a fresh PlatformRenderer for SSR operations
406+
// This ensures isolation between SSR calls and prevents state pollution
407+
// from previous rendering operations
408+
val platformRenderer = codes.yousef.summon.runtime.PlatformRenderer()
413409

414410
// Use the global renderToString helper which handles renderComposableRoot correctly
415411
val renderResult = renderToString(platformRenderer, rootComposable)

0 commit comments

Comments
 (0)