Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unsafe ref access during render #8053

Draft
wants to merge 1 commit into
base: add-million-lint-mode
Choose a base branch
from
Draft
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
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
Loading