use unique IDs for grid instances (#4132)
Previously, we had a single hard-coded DOM ID for grids. This meant that if you had multiple editors with grids on a page, they would all point at the svg `<defs>` from the first instance. Now, each grid generates a unique ID. ### Change type - [x] `bugfix` ### Release notes - Fix a bug causing multiple tldraw instances to share the same grid background
This commit is contained in:
parent
720b115a7e
commit
92fa5304f5
2 changed files with 5 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { modulate } from '@tldraw/utils'
|
import { modulate } from '@tldraw/utils'
|
||||||
import { useEditor } from '../../hooks/useEditor'
|
import { useEditor } from '../../hooks/useEditor'
|
||||||
|
import { useSafeId } from '../../hooks/useSafeId'
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export interface TLGridProps {
|
export interface TLGridProps {
|
||||||
|
@ -11,6 +12,7 @@ export interface TLGridProps {
|
||||||
|
|
||||||
/** @public @react */
|
/** @public @react */
|
||||||
export function DefaultGrid({ x, y, z, size }: TLGridProps) {
|
export function DefaultGrid({ x, y, z, size }: TLGridProps) {
|
||||||
|
const id = `grid_${useSafeId()}`
|
||||||
const editor = useEditor()
|
const editor = useEditor()
|
||||||
const { gridSteps } = editor.options
|
const { gridSteps } = editor.options
|
||||||
return (
|
return (
|
||||||
|
@ -26,8 +28,8 @@ export function DefaultGrid({ x, y, z, size }: TLGridProps) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<pattern
|
<pattern
|
||||||
key={`grid-pattern-${i}`}
|
key={i}
|
||||||
id={`grid-${step}`}
|
id={`${id}_${step}`}
|
||||||
width={s}
|
width={s}
|
||||||
height={s}
|
height={s}
|
||||||
patternUnits="userSpaceOnUse"
|
patternUnits="userSpaceOnUse"
|
||||||
|
@ -38,7 +40,7 @@ export function DefaultGrid({ x, y, z, size }: TLGridProps) {
|
||||||
})}
|
})}
|
||||||
</defs>
|
</defs>
|
||||||
{gridSteps.map(({ step }, i) => (
|
{gridSteps.map(({ step }, i) => (
|
||||||
<rect key={`grid-rect-${i}`} width="100%" height="100%" fill={`url(#grid-${step})`} />
|
<rect key={i} width="100%" height="100%" fill={`url(#${id}_${step})`} />
|
||||||
))}
|
))}
|
||||||
</svg>
|
</svg>
|
||||||
)
|
)
|
||||||
|
|
|
@ -161,9 +161,6 @@ export class TLLocalSyncClient {
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
onLoadError(error)
|
onLoadError(error)
|
||||||
showCantReadFromIndexDbAlert()
|
showCantReadFromIndexDbAlert()
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
window.location.reload()
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue