Skip to content

Allow JS root components to reinitialize on circuit restart - #7

Open
tomerqodo wants to merge 2 commits into
coderabbit_full_base_allow_js_root_components_to_reinitialize_on_circuit_restart_pr7from
coderabbit_full_head_allow_js_root_components_to_reinitialize_on_circuit_restart_pr7
Open

Allow JS root components to reinitialize on circuit restart#7
tomerqodo wants to merge 2 commits into
coderabbit_full_base_allow_js_root_components_to_reinitialize_on_circuit_restart_pr7from
coderabbit_full_head_allow_js_root_components_to_reinitialize_on_circuit_restart_pr7

Conversation

@tomerqodo

@tomerqodo tomerqodo commented Jan 29, 2026

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#7

Summary by CodeRabbit

  • New Features

    • Dynamic JavaScript root components now support per-renderer tracking.
  • Tests

    • Consolidated state persistence tests for dynamic JavaScript root components.

@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The changes implement per-renderer tracking for dynamic JavaScript root components by introducing a rendererId parameter to the API, consolidate E2E tests from a dedicated file into the main test suite, and simplify test configuration by removing a conditional flag and making component registration unconditional.

Changes

Cohort / File(s) Summary
Per-Renderer JS Component Tracking
src/Components/Web.JS/src/Rendering/JSRootComponents.ts, src/Components/Web.JS/src/Rendering/WebRendererInteropMethods.ts
Updated enableJSRootComponents to accept rendererId as first parameter, enabling per-renderer state tracking. Added guards to prevent multiple active renderers and reuse existing managers on re-enable. Defers initializer invocation to a one-time pass guarded by hasInitializedJsComponents flag.
Test Suite Reorganization
src/Components/test/E2ETest/Tests/StatePersistanceJSRootTest.cs, src/Components/test/E2ETest/Tests/StatePersistenceTest.cs
Deleted dedicated StatePersistanceJSRootTest.cs file; migrated its test logic into StatePersistenceTest.cs as new PersistentStateIsSupportedInDynamicJSRoots method with parameterized render mode variants.
Test Configuration Simplification
src/Components/test/testassets/Components.TestServer/Program.cs, src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs
Removed conditional registration logic based on RegisterDynamicJSRootComponent config flag; component registration now executes unconditionally. Removed corresponding test endpoint dictionary entry.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With renderers traced by their ID so bright,
Our components now balance with proper might,
Old tests consolidated, configuration neat,
Per-renderer tracking makes workflows complete! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is a benchmark reference link with no substantive detail about changes, objectives, impact, or testing. It fails to follow the required template structure with summary, description, and fix reference. Add a detailed description following the template: include a summary of changes (under 80 chars), detailed explanation of the feature, which issue it fixes, and confirmation of included tests and documentation.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Allow JS root components to reinitialize on circuit restart' directly reflects the main technical change: enabling per-renderer tracking so components can reinitialize when circuits restart.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch coderabbit_full_head_allow_js_root_components_to_reinitialize_on_circuit_restart_pr7

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.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sharoneyal

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sharoneyal

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/Components/Web.JS/src/Rendering/JSRootComponents.ts`:
- Around line 126-130: The guard in JSRootComponents.ts incorrectly throws when
the same renderer re-attaches; update the condition in the block that checks
manager and renderer ids so it only throws when a different renderer is present
(i.e., keep the check for manager but change the comparison between
currentRendererId and rendererId to detect inequality), allowing same-renderer
re-enable; refer to the variables manager, currentRendererId, and rendererId in
the JSRootComponents module to locate and fix the condition.
- Around line 136-138: When reassigning the renderer/manager (the lines that set
currentRendererId = rendererId and manager = managerInstance), also refresh the
cached component metadata by updating jsComponentParametersByIdentifier from the
new manager; e.g., call the managerInstance method that returns current
component parameter metadata (or invoke the existing refresh helper) and assign
its result to jsComponentParametersByIdentifier so dynamic root additions read
fresh metadata after re-init.

Comment on lines +126 to 130
if (manager && currentRendererId === rendererId) {
// A different renderer type (e.g., Server vs WebAssembly) is trying to enable JS root components.
// This is a multi-host scenario which is not supported for dynamic root components.
throw new Error('Dynamic root components have already been enabled.');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix renderer-id guard to allow same-renderer re-enable.
Line 126 currently throws when the same renderer re-attaches, which blocks circuit restart (the scenario this change targets). Flip the comparison to only throw on a different renderer id.

🔧 Proposed fix
-  if (manager && currentRendererId === rendererId) {
+  if (manager && currentRendererId !== rendererId) {
📝 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
if (manager && currentRendererId === rendererId) {
// A different renderer type (e.g., Server vs WebAssembly) is trying to enable JS root components.
// This is a multi-host scenario which is not supported for dynamic root components.
throw new Error('Dynamic root components have already been enabled.');
}
if (manager && currentRendererId !== rendererId) {
// A different renderer type (e.g., Server vs WebAssembly) is trying to enable JS root components.
// This is a multi-host scenario which is not supported for dynamic root components.
throw new Error('Dynamic root components have already been enabled.');
}
🤖 Prompt for AI Agents
In `@src/Components/Web.JS/src/Rendering/JSRootComponents.ts` around lines 126 -
130, The guard in JSRootComponents.ts incorrectly throws when the same renderer
re-attaches; update the condition in the block that checks manager and renderer
ids so it only throws when a different renderer is present (i.e., keep the check
for manager but change the comparison between currentRendererId and rendererId
to detect inequality), allowing same-renderer re-enable; refer to the variables
manager, currentRendererId, and rendererId in the JSRootComponents module to
locate and fix the condition.

Comment on lines +136 to +138
currentRendererId = rendererId;
manager = managerInstance;
jsComponentParametersByIdentifier = jsComponentParameters;

// Call the registered initializers. This is an arbitrary subset of the JS component types that are registered
// on the .NET side - just those of them that require some JS-side initialization (e.g., to register them
// as custom elements).
for (const [initializerIdentifier, componentIdentifiers] of Object.entries(jsComponentInitializers)) {
const initializerFunc = DotNet.findJSFunction(initializerIdentifier, 0) as JSComponentInitializerCallback;
for (const componentIdentifier of componentIdentifiers) {
const parameters = jsComponentParameters[componentIdentifier];
initializerFunc(componentIdentifier, parameters);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Refresh JS component parameter metadata on re-enable.
Line 137 updates the manager but never updates jsComponentParametersByIdentifier, so dynamic root additions can read undefined or stale metadata after re-init.

🛠️ Proposed fix
  currentRendererId = rendererId;
  manager = managerInstance;
+  jsComponentParametersByIdentifier = jsComponentParameters;
📝 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
currentRendererId = rendererId;
manager = managerInstance;
jsComponentParametersByIdentifier = jsComponentParameters;
// Call the registered initializers. This is an arbitrary subset of the JS component types that are registered
// on the .NET side - just those of them that require some JS-side initialization (e.g., to register them
// as custom elements).
for (const [initializerIdentifier, componentIdentifiers] of Object.entries(jsComponentInitializers)) {
const initializerFunc = DotNet.findJSFunction(initializerIdentifier, 0) as JSComponentInitializerCallback;
for (const componentIdentifier of componentIdentifiers) {
const parameters = jsComponentParameters[componentIdentifier];
initializerFunc(componentIdentifier, parameters);
currentRendererId = rendererId;
manager = managerInstance;
jsComponentParametersByIdentifier = jsComponentParameters;
🤖 Prompt for AI Agents
In `@src/Components/Web.JS/src/Rendering/JSRootComponents.ts` around lines 136 -
138, When reassigning the renderer/manager (the lines that set currentRendererId
= rendererId and manager = managerInstance), also refresh the cached component
metadata by updating jsComponentParametersByIdentifier from the new manager;
e.g., call the managerInstance method that returns current component parameter
metadata (or invoke the existing refresh helper) and assign its result to
jsComponentParametersByIdentifier so dynamic root additions read fresh metadata
after re-init.

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