fix: allow editor runtime styles under CSP

This commit is contained in:
lucaronin
2026-04-26 11:31:41 +02:00
parent 133242eff5
commit f58e9d8930
10 changed files with 118 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import { EditorView } from '@codemirror/view'
import { RUNTIME_STYLE_NONCE } from '../lib/runtimeStyleNonce'
import { useCodeMirror, type CodeMirrorCallbacks } from './useCodeMirror'
const noop = () => {}
@@ -31,6 +33,15 @@ describe('useCodeMirror', () => {
expect(container.querySelector('.cm-editor')).toBeInTheDocument()
})
it('tags generated CodeMirror style elements with the runtime CSP nonce', () => {
const ref = { current: container }
const { result } = renderHook(() =>
useCodeMirror(ref, 'hello world', noopCallbacks),
)
expect(result.current.current?.state.facet(EditorView.cspNonce)).toBe(RUNTIME_STYLE_NONCE)
})
it('calls requestMeasure when laputa-zoom-change event fires', () => {
const ref = { current: container }
const { result } = renderHook(() =>