fix(typst-preview): use RenderByContentOptions to avoid Rust aliasing
Build and Deploy Verso / deploy (push) Successful in 10m35s
Build and Deploy Verso / deploy (push) Successful in 10m35s
Replace runWithSession + manipulateData + session.renderToSvg with the
direct RenderByContentOptions form: renderer.renderToSvg({ format: 'vector',
artifactContent, container }).
The session-based API kept hitting 'recursive use of an object detected
which would lead to unsafe aliasing in rust' because runWithSession holds
a mutable borrow of the session while renderToSvg also takes one —
regardless of whether you call renderer.renderToSvg({ renderSession }) or
session.renderToSvg(). The content-based form creates and disposes the
session internally without any caller-visible borrow.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -71,11 +71,12 @@ const TypstWasmPreview: FC = () => {
|
||||
dataToRender = null
|
||||
|
||||
try {
|
||||
await renderer.runWithSession(async session => {
|
||||
session.manipulateData({ action: 'reset', data })
|
||||
// Use session.renderToSvg (NOT renderer.renderToSvg with renderSession)
|
||||
// to avoid double-aliasing the same Rust object inside runWithSession
|
||||
await session.renderToSvg({ container })
|
||||
// Use RenderByContentOptions: pass artifactContent directly instead of
|
||||
// using runWithSession + manipulateData, which causes Rust aliasing errors
|
||||
await renderer.renderToSvg({
|
||||
format: 'vector',
|
||||
artifactContent: data,
|
||||
container,
|
||||
})
|
||||
pendingVectorRef.current = null
|
||||
setStatus('ready')
|
||||
|
||||
Reference in New Issue
Block a user