Skip to content

Commit

Permalink
Update react (#459)
Browse files Browse the repository at this point in the history
- Updated react with breaking changes
- Updated react-dom with breaking changes
  • Loading branch information
duggalsu authored Nov 1, 2023
1 parent be9eff3 commit f29581c
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 130 deletions.
57 changes: 27 additions & 30 deletions browser-extension/plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions browser-extension/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"grommet-icons": "4.11.0",
"i18next": "23.6.0",
"prop-types": "15.8.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-feather": "2.0.10",
"react-i18next": "13.3.1",
"react-router-dom": "6.17.0",
Expand Down
8 changes: 4 additions & 4 deletions browser-extension/plugin/src/options.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { BrowserRouter as Router } from 'react-router-dom';
import { App } from './ui-components/pages/App';

const app = document.getElementById('app');
ReactDOM.render(
const root = createRoot(app);
root.render(
<Router>
<App />
</Router>,
app
</Router>
);
8 changes: 4 additions & 4 deletions browser-extension/plugin/src/transform-v2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
//import { parseTweet } from './twitter/parser';
import { parseTweet_v2 } from './twitter/parser-v2';
import { hashCode } from './util';
Expand Down Expand Up @@ -38,16 +38,16 @@ function addInlineMenu(id, item, hasSlur) {
let inlineButtonDiv = document.createElement('div');
inlineButtonDiv.id = id;
item.prepend(inlineButtonDiv);
let root = createRoot(inlineButtonDiv);

ReactDOM.render(
root.render(
<TweetControl
tweet={tweets[id]}
id={id}
debug={debug}
setBlur={setBlur}
hasSlur={hasSlur}
/>,
inlineButtonDiv
/>
);
}

Expand Down
8 changes: 4 additions & 4 deletions browser-extension/plugin/src/transform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { parseTweet } from './twitter/parser';
import { hashCode } from './util';
import { replaceSlur } from './slur-replace';
Expand Down Expand Up @@ -37,16 +37,16 @@ function addInlineMenu(id, item, hasSlur) {
let inlineButtonDiv = document.createElement('div');
inlineButtonDiv.id = id;
item.prepend(inlineButtonDiv);
let root = createRoot(inlineButtonDiv);

ReactDOM.render(
root.render(
<TweetControl
tweet={tweets[id]}
id={id}
debug={debug}
setBlur={setBlur}
hasSlur={hasSlur}
/>,
inlineButtonDiv
/>
);
}

Expand Down
8 changes: 4 additions & 4 deletions browser-extension/plugin/src/twitter/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2. Registering event handlers
*/

import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { InlineButtons } from '../ui-components/pages/InlineButtons';
import { pages, getPageType } from './pages';

Expand Down Expand Up @@ -32,9 +32,9 @@ function createTopBannerElement() {
var inlineButtonDiv = document.createElement('div');
inlineButtonDiv.id = 'ogbv-inline-button';
main.prepend(inlineButtonDiv);
ReactDOM.render(
<InlineButtons style={{ position: 'sticky', top: 0 }} />,
inlineButtonDiv
var root = createRoot(inlineButtonDiv);
root.render(
<InlineButtons style={{ position: 'sticky', top: 0 }} />
);
} catch (err) {
console.log('TEST : Error Creating Top Banner', err);
Expand Down
11 changes: 9 additions & 2 deletions browser-extension/plugin/src/twitter/tweet-controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ export function TweetControl({ tweet, id, setBlur, hasSlur, enableML }) {
// debug(id);
// }

useEffect(async () => {
await updateData();
useEffect(() => {
async function update() {
await updateData();
}
let ignore = false;
update();
return () => {
ignore = true;
};
}, []);

async function updateData() {
Expand Down
47 changes: 26 additions & 21 deletions browser-extension/plugin/src/ui-components/pages/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,33 @@ export function App() {
/**
* This loads an existing user into the UserContext at startup.
*/
useEffect(async () => {
try {
const userData = await getUserData();
const preferenceData = await getPreferenceData();

if (userData != undefined && Object.keys(userData).length !== 0) {
setUser(userData);
useEffect(() => {
async function navigatePreferences() {
try {
const userData = await getUserData();
const preferenceData = await getPreferenceData();

if(!ignore) {
if (userData != undefined && Object.keys(userData).length !== 0) {
setUser(userData);
}

if (preferenceData != undefined) {
const { language } = preferenceData;
i18n.changeLanguage(langNameMap[language]);

navigate('/preferences');
}
}
} catch (error) {
console.error('Error in useEffect:', error);
}

if (preferenceData != undefined) {
const { language } = preferenceData;
i18n.changeLanguage(langNameMap[language]);

navigate('/preferences');
}
} catch (error) {
console.error('Error in useEffect:', error);
}
// if (userData != undefined && Object.keys(userData).length != 0) {
// setUser(userData);
// }
// alert(process.env.API_URL);
}
let ignore = false;
navigatePreferences();
return () => {
ignore = true;
};
}, []);

let userBrowser;
Expand Down
17 changes: 13 additions & 4 deletions browser-extension/plugin/src/ui-components/pages/Archive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ export function Archive() {
const { user, setUser } = useContext(UserContext);
const { notification, showNotification } = useContext(NotificationContext);

useEffect(async () => {
const archive = await getArchive(user.accessToken);
console.log(archive);
setArchive(archive);
useEffect(() => {
async function archive() {
const archive = await getArchive(user.accessToken);
if(!ignore) {
console.log(archive);
setArchive(archive);
}
}
let ignore = false;
archive();
return () => {
ignore = true;
}
}, [user]);

return (
Expand Down
18 changes: 14 additions & 4 deletions browser-extension/plugin/src/ui-components/pages/Debug.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ export function Debug() {
const [localStorageData, setLocalStorageData] = useState(undefined);
const { t, i18n } = useTranslation();

useEffect(async () => {
const userData = await getUserData();
const preferenceData = await getPreferenceData();
setLocalStorageData({ user: userData, preference: preferenceData });
useEffect(() => {
async function localStorage() {
const userData = await getUserData();
const preferenceData = await getPreferenceData();
if(!ignore) {
setLocalStorageData({ user: userData, preference: preferenceData });
}

}
let ignore = false;
localStorage();
return () => {
ignore = true;
}
}, []);

async function clickReset() {
Expand Down
44 changes: 29 additions & 15 deletions browser-extension/plugin/src/ui-components/pages/InlineButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ export function InlineButtons() {
setPreferenceLS(preferenceData);
}

useEffect(async () => {
updateData();
useEffect(() => {
async function update() {
await updateData();
}
let ignore = false;
update();
return () => {
ignore = true;
};
}, []);

useEffect(() => {
Expand All @@ -82,19 +89,26 @@ export function InlineButtons() {
}
}, [preferenceLS]);

useEffect(async () => {
chrome.runtime.onMessage.addListener(async function (
message,
sender,
sendResponse
) {
switch (message.type) {
case 'updateData':
await updateData();
sendResponse('date updated');
break;
}
});
useEffect(() => {
async function messageListener() {
chrome.runtime.onMessage.addListener(async function (
message,
sender,
sendResponse
) {
switch (message.type) {
case 'updateData':
await updateData();
sendResponse('date updated');
break;
}
});
}
let ignore = false;
messageListener();
return () => {
ignore = true;
}
});

async function clickArchive() {
Expand Down
Loading

0 comments on commit f29581c

Please sign in to comment.