-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trigger should not render portal in ssr
- Loading branch information
Showing
4 changed files
with
60 additions
and
3 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,6 @@ | ||
/** | ||
* Portal will not work in SSR. We need wrap this to not to break. | ||
*/ | ||
export default function ServerPortal(): React.ReactElement { | ||
return null; | ||
} |
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,47 @@ | ||
import { cleanup } from '@testing-library/react'; | ||
import { hydrateRoot } from 'react-dom/client'; | ||
import { renderToString } from 'react-dom/server'; | ||
import Trigger from '../src'; | ||
|
||
global.canUseDOM = false; | ||
|
||
jest.mock('rc-util/lib/Dom/canUseDom', () => () => global.canUseDOM); | ||
|
||
describe('Trigger.SSR', () => { | ||
beforeEach(() => { | ||
global.canUseDOM = false; | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('normal', () => { | ||
const str = renderToString( | ||
<Trigger popupVisible popup={<strong>trigger</strong>} arrow> | ||
<div /> | ||
</Trigger>, | ||
); | ||
expect(str).toBeTruthy(); | ||
}); | ||
|
||
it('default visible should not block render', () => { | ||
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
const node = ( | ||
<Trigger popupVisible popup={<strong>trigger</strong>} arrow> | ||
<div /> | ||
</Trigger> | ||
); | ||
const str = renderToString(node); | ||
expect(str).toBeTruthy(); | ||
|
||
console.log(str); | ||
|
||
const div = document.createElement('div'); | ||
hydrateRoot(div, node); | ||
|
||
expect(errSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); |