-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpatch_header_portal.js
More file actions
37 lines (30 loc) · 1.17 KB
/
patch_header_portal.js
File metadata and controls
37 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require('fs');
let content = fs.readFileSync('components/header-search-button.tsx', 'utf8');
const oldUseEffect = ` useEffect(() => {
// Portals can only be used on the client-side after the DOM has mounted
setDesktopPortal(document.getElementById('header-search-portal'))
setMobilePortal(document.getElementById('mobile-header-search-portal'))
}, [])`;
const newUseEffect = ` useEffect(() => {
// Portals can only be used on the client-side after the DOM has mounted
setDesktopPortal(document.getElementById('header-search-portal'))
// Mobile portal might mount later, so check periodically
const checkMobilePortal = () => {
const el = document.getElementById('mobile-header-search-portal')
if (el) {
setMobilePortal(el)
return true
}
return false
}
if (!checkMobilePortal()) {
const interval = setInterval(() => {
if (checkMobilePortal()) {
clearInterval(interval)
}
}, 500)
return () => clearInterval(interval)
}
}, [])`;
content = content.replace(oldUseEffect, newUseEffect);
fs.writeFileSync('components/header-search-button.tsx', content);