Skip to content

Commit bebd72a

Browse files
refactor: address comments.
1 parent 201536a commit bebd72a

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

playwright/app.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@ test('clearing component source reports clear action without error status', asyn
344344
await expect(dialog).toHaveAttribute('open', '')
345345
await dialog.getByRole('button', { name: 'Clear' }).click()
346346

347+
await expect(page.locator('#preview-host button')).toHaveCount(0)
348+
await expect(page.locator('#preview-host pre')).toHaveCount(0)
347349
await expect(page.locator('#status')).toHaveText('Component cleared')
348350
await expect(page.locator('#status')).toHaveClass(/status--neutral/)
349-
await expect(page.locator('#preview-host pre')).toHaveCount(0)
350-
await expect(page.locator('#preview-host button')).toHaveCount(0)
351351
})
352352

353353
test('jsx syntax errors affect status but not diagnostics toggle severity', async ({

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ const clearComponentSource = () => {
472472
clearDiagnosticsScope('component')
473473
typeDiagnostics.clearTypeDiagnosticsState()
474474
setStatus('Component cleared', 'neutral')
475-
maybeRender()
475+
renderRuntime.clearPreview()
476476
}
477477

478478
const clearStylesSource = () => {

src/modules/render-runtime.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,24 @@ export const createRenderRuntimeController = ({
548548
}
549549
}
550550

551+
const hasComponentSource = () => getJsxSource().trim().length > 0
552+
553+
const clearPreview = () => {
554+
const target = getRenderTarget()
555+
clearTarget(target)
556+
}
557+
551558
const renderDom = async () => {
552559
const { jsx } = await ensureCoreRuntime()
553560
const target = getRenderTarget()
554561
clearTarget(target)
555562
const compiledStyles = await compileStyles()
556563
applyStyles(target, compiledStyles.css)
557564

565+
if (!hasComponentSource()) {
566+
return
567+
}
568+
558569
const renderFn = await evaluateUserModule()
559570
const output = renderFn ? renderFn(jsx) : null
560571
if (isDomNode(output)) {
@@ -577,6 +588,10 @@ export const createRenderRuntimeController = ({
577588
const compiledStyles = await compileStyles()
578589
applyStyles(target, compiledStyles.css)
579590

591+
if (!hasComponentSource()) {
592+
return
593+
}
594+
580595
const { reactJsx, createRoot, React } = await ensureReactRuntime()
581596
const renderFn = await evaluateUserModule({ jsx: reactJsx, reactJsx, React })
582597
if (!renderFn) {
@@ -635,6 +650,7 @@ export const createRenderRuntimeController = ({
635650
}
636651

637652
return {
653+
clearPreview,
638654
renderPreview,
639655
scheduleRender,
640656
setStyleCompiling,

0 commit comments

Comments
 (0)