-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssr): use useId for hydration and remove the need for resetServer…
…Context (React 18+) (#439) * feat(ssr): remove need for resetServerContext when useId is available (i.e. React 18+) * refactor: add deprecated prefix to some functions (with test utils) * test(process.env): add missing types for the csp-server Co-authored-by: klarstrup <[email protected]>
- Loading branch information
Showing
12 changed files
with
108 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
interface ProcessEnv { | ||
NODE_ENV?: 'development' | 'production'; | ||
REACT_MAJOR_VERSION?: '16' | '17' | '18'; | ||
CI?: boolean; | ||
} | ||
|
||
interface Process { | ||
env: ProcessEnv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import React from 'react'; | ||
import { useMemo } from 'use-memo-one'; | ||
import type { ContextId } from '../../types'; | ||
|
||
let count = 0; | ||
|
||
export function reset() { | ||
export function resetDeprecatedUniqueContextId() { | ||
count = 0; | ||
} | ||
|
||
export default function useInstanceCount(): ContextId { | ||
function useDeprecatedUniqueContextId(): ContextId { | ||
return useMemo(() => `${count++}`, []); | ||
} | ||
|
||
function useUniqueContextId(): ContextId { | ||
return React.useId(); | ||
} | ||
|
||
// The useId hook is only available in React 18+ | ||
export default 'useId' in React | ||
? useUniqueContextId | ||
: useDeprecatedUniqueContextId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...t/integration/server-side-rendering/__react_18_snapshots__/server-rendering.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should support rendering to a string 1`] = `"<main><div data-rfd-droppable-id="droppable" data-rfd-droppable-context-id="0"><div data-rfd-draggable-context-id="0" data-rfd-draggable-id="0" tabindex="0" role="button" aria-describedby="rfd-hidden-text-0-hidden-text-0" data-rfd-drag-handle-draggable-id="0" data-rfd-drag-handle-context-id="0" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="0">item: <!-- -->0</div><div data-rfd-draggable-context-id="0" data-rfd-draggable-id="1" tabindex="0" role="button" aria-describedby="rfd-hidden-text-0-hidden-text-0" data-rfd-drag-handle-draggable-id="1" data-rfd-drag-handle-context-id="0" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="1">item: <!-- -->1</div><div data-rfd-draggable-context-id="0" data-rfd-draggable-id="2" tabindex="0" role="button" aria-describedby="rfd-hidden-text-0-hidden-text-0" data-rfd-drag-handle-draggable-id="2" data-rfd-drag-handle-context-id="0" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="2">item: <!-- -->2</div></div></main>"`; | ||
exports[`should support rendering to a string 1`] = `"<main><div data-rfd-droppable-id="droppable" data-rfd-droppable-context-id=":R0:"><div data-rfd-draggable-context-id=":R0:" data-rfd-draggable-id="0" tabindex="0" role="button" aria-describedby="rfd-hidden-text-:R0:-hidden-text-:R1:" data-rfd-drag-handle-draggable-id="0" data-rfd-drag-handle-context-id=":R0:" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="0">item: <!-- -->0</div><div data-rfd-draggable-context-id=":R0:" data-rfd-draggable-id="1" tabindex="0" role="button" aria-describedby="rfd-hidden-text-:R0:-hidden-text-:R1:" data-rfd-drag-handle-draggable-id="1" data-rfd-drag-handle-context-id=":R0:" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="1">item: <!-- -->1</div><div data-rfd-draggable-context-id=":R0:" data-rfd-draggable-id="2" tabindex="0" role="button" aria-describedby="rfd-hidden-text-:R0:-hidden-text-:R1:" data-rfd-drag-handle-draggable-id="2" data-rfd-drag-handle-context-id=":R0:" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="2">item: <!-- -->2</div></div></main>"`; | ||
|
||
exports[`should support rendering to static markup 1`] = `"<main><div data-rfd-droppable-id="droppable" data-rfd-droppable-context-id="0"><div data-rfd-draggable-context-id="0" data-rfd-draggable-id="0" tabindex="0" role="button" aria-describedby="rfd-hidden-text-0-hidden-text-0" data-rfd-drag-handle-draggable-id="0" data-rfd-drag-handle-context-id="0" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="0">item: 0</div><div data-rfd-draggable-context-id="0" data-rfd-draggable-id="1" tabindex="0" role="button" aria-describedby="rfd-hidden-text-0-hidden-text-0" data-rfd-drag-handle-draggable-id="1" data-rfd-drag-handle-context-id="0" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="1">item: 1</div><div data-rfd-draggable-context-id="0" data-rfd-draggable-id="2" tabindex="0" role="button" aria-describedby="rfd-hidden-text-0-hidden-text-0" data-rfd-drag-handle-draggable-id="2" data-rfd-drag-handle-context-id="0" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="2">item: 2</div></div></main>"`; | ||
exports[`should support rendering to static markup 1`] = `"<main><div data-rfd-droppable-id="droppable" data-rfd-droppable-context-id=":R0:"><div data-rfd-draggable-context-id=":R0:" data-rfd-draggable-id="0" tabindex="0" role="button" aria-describedby="rfd-hidden-text-:R0:-hidden-text-:R1:" data-rfd-drag-handle-draggable-id="0" data-rfd-drag-handle-context-id=":R0:" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="0">item: 0</div><div data-rfd-draggable-context-id=":R0:" data-rfd-draggable-id="1" tabindex="0" role="button" aria-describedby="rfd-hidden-text-:R0:-hidden-text-:R1:" data-rfd-drag-handle-draggable-id="1" data-rfd-drag-handle-context-id=":R0:" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="1">item: 1</div><div data-rfd-draggable-context-id=":R0:" data-rfd-draggable-id="2" tabindex="0" role="button" aria-describedby="rfd-hidden-text-:R0:-hidden-text-:R1:" data-rfd-drag-handle-draggable-id="2" data-rfd-drag-handle-context-id=":R0:" draggable="false" data-is-dragging="false" data-is-drop-animating="false" data-is-combining="false" data-is-combine-target="false" data-is-clone="false" data-testid="2">item: 2</div></div></main>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import getReactMajorVersion from './get-react-major-version'; | ||
|
||
export default function invokeOnReactVersion( | ||
reactVersion: Array<'16' | '17' | '18'>, | ||
callback: () => void, | ||
) { | ||
if (reactVersion.includes(getReactMajorVersion())) { | ||
callback(); | ||
} | ||
} |
bcb66d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dnd – ./
dnd-navy.vercel.app
dnd-git-main-hello-pangea.vercel.app
dnd.hellopangea.com
dnd-hello-pangea.vercel.app