Skip to content

Commit

Permalink
fix: remove unsafe ref access during render
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Dec 13, 2024
1 parent 9d075f4 commit f3c04dc
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
inspectors: inspectorsResolver,
},
} = useSource()
const telemetry = useTelemetry()
const presenceStore = usePresenceStore()
const paneRouter = usePaneRouter()
const setPaneParams = paneRouter.setParams
Expand Down Expand Up @@ -297,14 +298,15 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
const patchRef = useRef<(event: PatchEvent) => void>(() => {
throw new Error('Nope')
})

patchRef.current = (event: PatchEvent) => {
// when creating a new draft
if (!editState.draft && !editState.published) {
telemetry.log(CreatedDraft)
useEffect(() => {
patchRef.current = (event: PatchEvent) => {
// when creating a new draft
if (!editState.draft && !editState.published) {
telemetry.log(CreatedDraft)
}
patch.execute(toMutationPatches(event.patches), initialValue.value)
}
patch.execute(toMutationPatches(event.patches), initialValue.value)
}
}, [editState.draft, editState.published, initialValue.value, patch, telemetry])

const handleChange = useCallback((event: PatchEvent) => patchRef.current(event), [])

Expand Down Expand Up @@ -411,8 +413,6 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
[inspectOpen, params, setPaneParams],
)

const telemetry = useTelemetry()

const handleMenuAction = useCallback(
(item: PaneMenuItem) => {
if (item.action === 'production-preview' && previewUrl) {
Expand Down Expand Up @@ -581,7 +581,9 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
}, [documentId, documentType, schemaType, handleChange, setDocumentMeta])

const formStateRef = useRef(formState)
formStateRef.current = formState
useEffect(() => {
formStateRef.current = formState
}, [formState])

const setOpenPath = useCallback(
(path: Path) => {
Expand Down

0 comments on commit f3c04dc

Please sign in to comment.