Commit 211257c
authored
Harden renderer teardown polish
Closes #3647
## Summary
- Centralize `isRendererTeardownResult` in
`packages/react-on-rails/src/rendererTeardown.ts` and expose it as
`react-on-rails/@internal/rendererTeardown`, so OSS and Pro share one
teardown-result guard instead of carrying inline copies.
- Keep the Pro `wrapServerComponentRenderer/client` runtime guard so
teardown-shaped server-component render results fail with a clear error
before the generic component-shape check.
- Harden and clarify the renderer teardown tests around same-id async
races, DOM descriptor reuse, and Pro wrapper validation cleanup.
- Keep Pro parity coverage for non-native thenable teardown rejection
handling.
## Tests
- `pnpm install --frozen-lockfile`
- `pnpm exec prettier --check
packages/react-on-rails/src/rendererTeardown.ts
packages/react-on-rails/src/ClientRenderer.ts
packages/react-on-rails/src/createReactOutput.ts
packages/react-on-rails-pro/src/ClientSideRenderer.ts
packages/react-on-rails-pro/src/wrapServerComponentRenderer/client.tsx
packages/react-on-rails/tests/ClientRenderer.test.ts
packages/react-on-rails/package.json`
- `pnpm exec eslint --no-warn-ignored
packages/react-on-rails/src/rendererTeardown.ts
packages/react-on-rails/src/ClientRenderer.ts
packages/react-on-rails/src/createReactOutput.ts
packages/react-on-rails-pro/src/ClientSideRenderer.ts
packages/react-on-rails-pro/src/wrapServerComponentRenderer/client.tsx
packages/react-on-rails/tests/ClientRenderer.test.ts`
- `pnpm --filter react-on-rails run type-check`
- `pnpm --filter react-on-rails-pro run type-check`
- `pnpm --filter react-on-rails exec jest tests/ClientRenderer.test.ts
--runInBand`
- `pnpm --filter react-on-rails-pro exec jest
tests/ClientSideRenderer.test.ts
tests/wrapServerComponentRenderer.client.test.jsx --runInBand`
- `pnpm --filter react-on-rails run build`
- `pnpm --filter react-on-rails-pro run build`
- Follow-up focused reruns after review-comment cleanup: `pnpm exec
prettier --check packages/react-on-rails/tests/ClientRenderer.test.ts
packages/react-on-rails-pro/tests/wrapServerComponentRenderer.client.test.jsx`,
`pnpm exec eslint --no-warn-ignored
packages/react-on-rails/tests/ClientRenderer.test.ts
packages/react-on-rails-pro/tests/wrapServerComponentRenderer.client.test.jsx`,
`pnpm --filter react-on-rails exec jest tests/ClientRenderer.test.ts
--runInBand`, `pnpm --filter react-on-rails-pro exec jest
tests/wrapServerComponentRenderer.client.test.jsx --runInBand`.
## Design Calls
- Added an internal OSS export instead of documenting three synchronized
`isRendererTeardownResult` copies; Pro already consumes OSS internal
subpaths, and this keeps the guard shape single-sourced.
- Kept `invokeRendererTeardown` duplicated; that helper still has
package-specific runtime/logging context and remains covered by parity
tests.
- Kept public `RendererFunction` return typing unchanged pending
downstream migration data.
- Left docs and dummy-app renderer conversions out of this PR per scope;
this PR stays focused on renderer teardown diagnostics, guard reuse, and
targeted tests.
- No changelog entry: this is Pro/OSS renderer hardening plus an
invalid-shape diagnostic guard, not a new user-facing feature or
documented behavior change.
Labels: none. This is a focused test/diagnostic hardening PR with no CI
workflow, dependency, generator, SSR output, or broad Pro/core boundary
changes.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Internal guard deduplication and stricter runtime validation for
invalid server-component render shapes; behavior changes are limited to
clearer errors and test-documented teardown edge cases, with no auth or
data-path changes.
>
> **Overview**
> **Centralizes** the `isRendererTeardownResult` type guard in
`rendererTeardown.ts` and exposes it as
`react-on-rails/@internal/rendererTeardown`, replacing inline copies in
OSS (`ClientRenderer`, `createReactOutput`) and Pro
(`ClientSideRenderer`, `wrapServerComponentRenderer/client`).
>
> **Pro RSC wrapper** now rejects server-component render functions that
resolve to a teardown object with an explicit error (before DOM/context
checks), closing #3647-style misconfiguration diagnostics.
>
> **Tests** add coverage for non-native thenable teardown rejections
(Pro), same-id async teardown races where a stale renderer must not
overwrite a newer mount (OSS), and `wrapServerComponentRenderer`
validation for missing `domNodeId`, DOM node, `railsContext`, and
teardown-shaped returns; webpack manifest test aliases the new internal
module.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b92db44. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Added runtime validation that rejects invalid server-rendered results
(e.g., teardown objects) with clearer error messages.
* Improved handling and logging when asynchronous renderer teardown or
replacement fails or races.
* Improved validation and error messages for missing mount target or
missing context during server-component mounting.
* **Tests**
* Expanded tests for server component rendering validation edge cases.
* Added tests ensuring async renderer teardown/replacement logs
correctly for promise/thenable scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 23e8d8f commit 211257c
10 files changed
Lines changed: 216 additions & 172 deletions
File tree
- packages
- react-on-rails-pro
- src
- wrapServerComponentRenderer
- tests
- react-on-rails
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 77 | | |
86 | 78 | | |
87 | 79 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
78 | 89 | | |
79 | 90 | | |
80 | 91 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
398 | 434 | | |
399 | 435 | | |
400 | 436 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
Lines changed: 80 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
40 | 120 | | |
41 | 121 | | |
42 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 44 | | |
53 | 45 | | |
54 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 2 | + | |
9 | 3 | | |
| 4 | + | |
10 | 5 | | |
11 | 6 | | |
12 | 7 | | |
13 | 8 | | |
14 | 9 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 10 | | |
24 | 11 | | |
25 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments