Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion playwright/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,10 @@ test('clearing component source reports clear action without error status', asyn
await expect(dialog).toHaveAttribute('open', '')
await dialog.getByRole('button', { name: 'Clear' }).click()

await expect(page.locator('#preview-host button')).toHaveCount(0)
await expect(page.locator('#preview-host pre')).toHaveCount(0)
await expect(page.locator('#status')).toHaveText('Component cleared')
await expect(page.locator('#status')).toHaveClass(/status--neutral/)
await expect(page.locator('#preview-host pre')).toHaveCount(0)
})

test('jsx syntax errors affect status but not diagnostics toggle severity', async ({
Expand Down
9 changes: 2 additions & 7 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,14 @@ const clearComponentSource = () => {
clearDiagnosticsScope('component')
typeDiagnostics.clearTypeDiagnosticsState()
setStatus('Component cleared', 'neutral')

if (!jsxCodeEditor) {
maybeRender()
}
renderRuntime.clearPreview()
}

const clearStylesSource = () => {
setCssSource('')
clearDiagnosticsScope('styles')
setStatus('Styles cleared', 'neutral')
if (!cssCodeEditor) {
maybeRender()
}
maybeRender()
}

const confirmClearSource = ({ label, onConfirm }) => {
Expand Down
16 changes: 16 additions & 0 deletions src/modules/render-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,24 @@ export const createRenderRuntimeController = ({
}
}

const hasComponentSource = () => getJsxSource().trim().length > 0

const clearPreview = () => {
const target = getRenderTarget()
clearTarget(target)
}

const renderDom = async () => {
const { jsx } = await ensureCoreRuntime()
const target = getRenderTarget()
clearTarget(target)
const compiledStyles = await compileStyles()
applyStyles(target, compiledStyles.css)

if (!hasComponentSource()) {
return
}

const renderFn = await evaluateUserModule()
const output = renderFn ? renderFn(jsx) : null
if (isDomNode(output)) {
Expand All @@ -577,6 +588,10 @@ export const createRenderRuntimeController = ({
const compiledStyles = await compileStyles()
applyStyles(target, compiledStyles.css)

if (!hasComponentSource()) {
return
}

const { reactJsx, createRoot, React } = await ensureReactRuntime()
const renderFn = await evaluateUserModule({ jsx: reactJsx, reactJsx, React })
if (!renderFn) {
Expand Down Expand Up @@ -635,6 +650,7 @@ export const createRenderRuntimeController = ({
}

return {
clearPreview,
renderPreview,
scheduleRender,
setStyleCompiling,
Expand Down