Added auto resize to transistor embed card#26798
Conversation
ref https://linear.app/ghost/issue/NY-1149/ - once transistor implements a postMessage for emitting the size, we can listen to it and adjust accordingly
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughReplaced 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.js`:
- Around line 180-187: Replace the weak source-only gating in the message
handler with an origin check and a finite-number height guard: inside the
window.addEventListener('message', ...) handler (and where iframe and
iframe.contentWindow are used), verify event.origin === the expected Transistor
origin (e.g. a TRANSISTOR_ORIGIN constant or the literal
'https://partner.transistor.fm') in addition to the existing
iframe.contentWindow === event.source check, and change the height validation
from typeof event.data.height === 'number' to
Number.isFinite(event.data.height') so NaN/Infinity are rejected before setting
iframe.style.height.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: edf47381-5207-4f04-9ae8-1cb2ab820455
📒 Files selected for processing (2)
ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.jsghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js
🤖 Velo CI Failure AnalysisClassification: 🟠 SOFT FAIL
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js (1)
42-47: Avoid pinning this test to exact script internals.These checks are coupled to the current
buildEmbedScript()implementation: helper names, property access spelling, and the specific numeric guard. A harmless refactor inghost/core/core/server/services/koenig/node-renderers/transistor-renderer.js:104-190will fail this test even if resize support still works. Prefer asserting the stable renderer contract here, or executing the emitted script in a DOM-style test if you want behavioral coverage for the resize path.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js` around lines 42 - 47, The test is brittle because it asserts internals of buildEmbedScript() (helper names like colorToRgb, initTransistorEmbed, property access text, and Number.isSafeInteger) instead of the stable renderer contract; update transistor-renderer.test.js to stop checking those exact script internals and instead assert the stable outputs of renderTransistorNode (e.g., that result.html contains a <script> tag and the expected embed container/attributes or that the script executes by running it in a DOM-like environment), or replace the string-inclusion assertions with higher-level checks such as verifying the embed container markup, partner host (partner.transistor.fm) presence, and that the script tag exists, or add a DOM-execution test to verify resize behavior rather than checking helper names; locate buildEmbedScript() and renderTransistorNode() in the transistor-renderer test to apply these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@ghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js`:
- Around line 42-47: The test is brittle because it asserts internals of
buildEmbedScript() (helper names like colorToRgb, initTransistorEmbed, property
access text, and Number.isSafeInteger) instead of the stable renderer contract;
update transistor-renderer.test.js to stop checking those exact script internals
and instead assert the stable outputs of renderTransistorNode (e.g., that
result.html contains a <script> tag and the expected embed container/attributes
or that the script executes by running it in a DOM-like environment), or replace
the string-inclusion assertions with higher-level checks such as verifying the
embed container markup, partner host (partner.transistor.fm) presence, and that
the script tag exists, or add a DOM-execution test to verify resize behavior
rather than checking helper names; locate buildEmbedScript() and
renderTransistorNode() in the transistor-renderer test to apply these changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 68e6dbe7-84c7-447b-90aa-64efbb76e16e
📒 Files selected for processing (2)
ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.jsghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js
✅ Files skipped from review due to trivial changes (1)
- ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js (1)
39-47: Strengthen resize-script assertions to cover safety-critical behaviorThese checks are currently token-based and may pass even if the listener stops enforcing origin/source checks or applying height. Consider asserting those exact behaviors in the emitted script too.
Suggested test hardening
it('renders embed script with background detection and resize listener', function () { const result = renderForWeb(getTestData()); assert.ok(result.html.includes('<script>')); assert.ok(result.html.includes('initTransistorEmbed')); assert.ok(result.html.includes('colorToRgb')); assert.ok(result.html.includes('event.data.type === \'resize\'')); assert.ok(result.html.includes('iframeOrigin')); assert.ok(result.html.includes('Number.isSafeInteger')); + assert.match(result.html, /event\.origin\s*===\s*iframeOrigin/); + assert.match(result.html, /event\.source\s*===\s*iframe\.contentWindow/); + assert.match(result.html, /height\s*=\s*.*px/); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js` around lines 39 - 47, Update the unit test in transistor-renderer.test.js to assert the emitted resize listener enforces origin/source checks and actually applies the height: when calling renderForWeb(getTestData()) verify the generated script contains explicit origin/source validation (e.g., references to iframe.contentWindow or checks like event.source === iframe.contentWindow and/or event.origin === iframeOrigin) and contains the exact assignment that applies height to the iframe (e.g., setting iframe.style.height or assigning to iframe.height after verifying Number.isSafeInteger on the parsed value). Keep the existing token checks but add these concrete string assertions so the resize listener behavior in the output script is enforced.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@ghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js`:
- Around line 39-47: Update the unit test in transistor-renderer.test.js to
assert the emitted resize listener enforces origin/source checks and actually
applies the height: when calling renderForWeb(getTestData()) verify the
generated script contains explicit origin/source validation (e.g., references to
iframe.contentWindow or checks like event.source === iframe.contentWindow and/or
event.origin === iframeOrigin) and contains the exact assignment that applies
height to the iframe (e.g., setting iframe.style.height or assigning to
iframe.height after verifying Number.isSafeInteger on the parsed value). Keep
the existing token checks but add these concrete string assertions so the resize
listener behavior in the output script is enforced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2e8d0ce8-1592-4440-b79c-9eb76fab3145
📒 Files selected for processing (2)
ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.jsghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
- ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.js
E2E Tests FailedTo view the Playwright test report locally, run: REPORT_DIR=$(mktemp -d) && gh run download 23025385614 -n playwright-report -D "$REPORT_DIR" && npx playwright show-report "$REPORT_DIR" |
🤖 Velo CI Failure AnalysisClassification: 🟠 SOFT FAIL
|
This reverts commit 49f4986.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.js (1)
145-156: Optional: simplify fallback branching forel.src.This currently works, but you can reduce duplicate fallback assignments by computing a single final URL and assigning once.
♻️ Small cleanup
- if (!node || !bg || bg === 'transparent') { - el.src = baseSrc; - } else { - const {r, g, b, a} = colorToRgb(bg); - if (a === 0) { - el.src = baseSrc; - } else { - const hex = [r, g, b].map(c => c.toString(16).padStart(2, '0')).join(''); - const u = new URL(baseSrc); - u.searchParams.set('background', hex); - el.src = u.toString(); - } - } + let finalSrc = baseSrc; + if (node && bg && bg !== 'transparent') { + const {r, g, b, a} = colorToRgb(bg); + if (a > 0) { + const hex = [r, g, b].map(c => c.toString(16).padStart(2, '0')).join(''); + const u = new URL(baseSrc); + u.searchParams.set('background', hex); + finalSrc = u.toString(); + } + } + el.src = finalSrc;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.js` around lines 145 - 156, The current branching assigns el.src in multiple places; simplify by computing a single finalSrc and assigning el.src once: default finalSrc = baseSrc, then only if node && bg && bg !== 'transparent' call colorToRgb(bg), check that a !== 0, build the hex from [r,g,b], create a new URL(baseSrc), set u.searchParams.set('background', hex'), set finalSrc = u.toString(), and finally assign el.src = finalSrc (use the existing symbols node, bg, colorToRgb, baseSrc, hex, URL, u, and el.src).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.js`:
- Around line 145-156: The current branching assigns el.src in multiple places;
simplify by computing a single finalSrc and assigning el.src once: default
finalSrc = baseSrc, then only if node && bg && bg !== 'transparent' call
colorToRgb(bg), check that a !== 0, build the hex from [r,g,b], create a new
URL(baseSrc), set u.searchParams.set('background', hex'), set finalSrc =
u.toString(), and finally assign el.src = finalSrc (use the existing symbols
node, bg, colorToRgb, baseSrc, hex, URL, u, and el.src).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 49d6b4ec-2ae3-4f37-8b80-d0ca0f07d986
📒 Files selected for processing (2)
ghost/core/core/server/services/koenig/node-renderers/transistor-renderer.jsghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
- ghost/core/test/unit/server/services/koenig/node-renderers/transistor-renderer.test.js
🤖 Velo CI Failure AnalysisClassification: 🟠 SOFT FAIL
|
ref https://linear.app/ghost/issue/NY-1149/