Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/perf-dialog-stable-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Use stable object reference for DialogContext value to prevent unnecessary re-renders
Comment on lines +1 to +5
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR metadata indicates tests were “Added/updated”, but this PR only changes the Dialog context value and adds a changeset (no test updates). Please either update the checklist/description to reflect reality, or add coverage that would fail if the context value regressed to an unstable reference.

Copilot uses AI. Check for mistakes.
3 changes: 2 additions & 1 deletion packages/react/src/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ const defaultFooterButtons: Array<DialogButtonProps> = []

// useful to determine whether we're inside a Dialog from a nested component
export const DialogContext = React.createContext<object | undefined>(undefined)
const DIALOG_CONTEXT_VALUE = Object.freeze({})

const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogProps>>((props, forwardedRef) => {
const {
Expand Down Expand Up @@ -348,7 +349,7 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
)

return (
<DialogContext.Provider value={{}}>
<DialogContext.Provider value={DIALOG_CONTEXT_VALUE}>
<Portal>
<div
ref={backdropRef}
Expand Down
Loading