Skip to content

Conversation

@PythonFZ
Copy link
Member

@PythonFZ PythonFZ commented Jan 19, 2026

Known issue:

  1. attach camera to curve
  2. toggle pathtracing on
  3. toggle it off
  4. detach camera from curve
    Now positions is 0,0,0 and the camera only becomes responsive again, when setting positions manually.
    Also webgl context loss on pathtracing changes.

When pathtracing was toggled, cameras using CurveAttachment positions would reset to the first point of the curve instead of maintaining their current position.

Root cause: PathTracingRenderer returned different component types depending on pathtracing state (Fragment vs Pathtracer), causing React to remount children. When Camera remounted, its state reinitialized to the first curve point instead of the resolved CurveAttachment position.

Changes:

  • PathTracingRenderer: Always render Pathtracer with enabled prop to maintain stable React tree structure and prevent child remounting
  • Canvas: Remove pathtracingEnabled from Canvas key (unnecessary)
  • Curve: Return empty group instead of null when pathtracing enabled to keep curveRef registered for CurveAttachment resolution

Summary by CodeRabbit

  • Bug Fixes

    • Prevented unnecessary remounts when toggling path tracing and ensured 3D attachments remain resolvable during path tracing.
    • Pathtracer now correctly respects the enabled setting and omits related updaters when disabled.
  • Improvements

    • Smoother, more stable camera positioning and interpolation, including curve-based interpolation for transitions and loading.
  • Refactor

    • Unified and simplified camera and rendering logic for more consistent behavior.
  • Chore

    • Adjusted screenshot membership/permission check on the server side.

✏️ Tip: You can customize this high-level summary in your review settings.

When pathtracing was toggled, cameras using CurveAttachment positions
would reset to the first point of the curve instead of maintaining
their current position.

Root cause: PathTracingRenderer returned different component types
depending on pathtracing state (Fragment vs Pathtracer), causing React
to remount children. When Camera remounted, its state reinitialized
to the first curve point instead of the resolved CurveAttachment position.

Changes:
- PathTracingRenderer: Always render Pathtracer with enabled prop to
  maintain stable React tree structure and prevent child remounting
- Canvas: Remove pathtracingEnabled from Canvas key (unnecessary)
- Curve: Return empty group instead of null when pathtracing enabled
  to keep curveRef registered for CurveAttachment resolution

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

Memoized camera position resolution added via a new resolvePosition utility and integrated into Canvas and Camera; PathTracing rendering now respects the enabled flag and conditionally mounts updater/capture/environment; Curve components remain mounted during pathtracing; server-side membership check changed from RoomKeys.members() to RoomKeys.users().

Changes

Cohort / File(s) Summary
Camera utilities & resolution
app/src/utils/cameraUtils.ts
Added interpolateCurvePosition and resolvePosition to resolve direct coordinates or CurveAttachment references from geometries.
Camera component refactor
app/src/components/three/Camera.tsx
Replaced inline position/target resolution with resolveToVector3 that uses resolvePosition/curve interpolation; unified projection updates and simplified camera-type handling.
Canvas position memoization
app/src/components/Canvas.tsx
Introduced useMemo + resolvePosition to compute cameraPosition from sessionCameraData.position (default [0,0,10]) before early returns.
Pathtracing gating & renderer
app/src/components/PathTracingRenderer.tsx
Use actual enabled prop for Pathtracer; render PathtracingUpdater, PathtracingCaptureProvider, and Environment only when enabled (and environment preset not "none").
Curve mounting behavior
app/src/components/three/Curve.tsx
When pathtracing is enabled, mount an empty <group /> instead of returning null to preserve curveRef registration for attachments.
Server session route change
src/zndraw/app/session_routes.py
Switched membership verification from RoomKeys.members() to RoomKeys.users() in request_screenshot.

Sequence Diagram(s)

(omitted — changes are internal/conditional rendering and utilities that do not introduce a new multi-component sequential workflow warranting a diagram)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Feat/screenshot system improvements #864: Modifies the screenshot/capture and pathtracing subsystems (frontend capture/providers and backend screenshot endpoints), likely related to these rendering and capture changes.

Poem

🐰
I hop through vectors, soft and spry,
I memoize the camera sky.
Curves stay planted, waiting near,
Pathtraces whisper, "Mount, not clear."
A rabbit cheers — the render's here!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main issue being fixed: preventing camera reset when toggling pathtracing with CurveAttachment, which is the root cause addressed across multiple component changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Changed room_keys.members() to room_keys.users() - the members() method
doesn't exist on RoomKeys class.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/components/PathTracingRenderer.tsx (1)

45-48: Remove Fragment fallback to maintain stable component tree and prevent unnecessary remounts.

Lines 24-25 return a Fragment when enabled is false, which changes the wrapper type based on the enabled state. This violates the pattern already established on line 8 (which renders <Pathtracer enabled={false}> for loading state) and can cause remounts when the enabled prop changes. Always render Pathtracer and let the enabled prop control behavior, as shown in the suggested fix.

Suggested fix
-	// Pass through if not enabled
-	if (!enabled) {
-		return <>{children}</>;
-	}
-
-	return (
-		<Pathtracer
-			minSamples={min_samples}
-			samples={samples}
-			bounces={bounces}
-			tiles={tiles}
-			enabled={enabled}
-		>
+	return (
+		<Pathtracer
+			minSamples={min_samples}
+			samples={samples}
+			bounces={bounces}
+			tiles={tiles}
+			enabled={enabled}
+		>
 			{enabled && <PathtracingUpdater settings={settings} />}
 			{enabled && <PathtracingCaptureProvider />}
 			{enabled && environment_preset !== "none" && (
 				<Environment
 					preset={environment_preset}
 					background={environment_background}
 					backgroundBlurriness={environment_blur}
 					environmentIntensity={environment_intensity}
 				/>
 			)}
 			{children}
 		</Pathtracer>
 	);

@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.79%. Comparing base (731ce39) to head (9f9c252).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/zndraw/app/session_routes.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #866      +/-   ##
==========================================
- Coverage   79.81%   79.79%   -0.02%     
==========================================
  Files         165      165              
  Lines       20213    20213              
==========================================
- Hits        16133    16129       -4     
- Misses       4080     4084       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PythonFZ PythonFZ merged commit 7796a5d into main Jan 19, 2026
6 checks passed
@PythonFZ PythonFZ deleted the fix/camera-reset-pathtracing-toggle branch January 19, 2026 20:41
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.

3 participants