Skip to content

Commit

Permalink
fix: fix ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
aelf-lxy committed Aug 7, 2024
1 parent aed24c5 commit 76090a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/login/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-web-login",
"version": "2.1.4",
"version": "2.1.5",
"main": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
Expand Down
52 changes: 26 additions & 26 deletions packages/login/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,32 +590,32 @@ function WebLoginProvider({

export default function Provider({ children, ...props }: WebLoginProviderProps) {
const aelfReactConfig = getConfig().aelfReact;
const TELEGRAM_SRC = 'https://telegram.org/js/telegram-web-app.js';

const [scriptLoaded, setScriptLoaded] = useState(false);

useEffect(() => {
if (typeof window !== 'undefined' && typeof location !== 'undefined') {
const script = document.createElement('script');
script.src = TELEGRAM_SRC;
script.type = 'text/javascript';
script.onload = () => {
setScriptLoaded(true);
};

script.onerror = () => {
console.error('Failed to load the Telegram script');
setScriptLoaded(false);
};
document.head.appendChild(script);
return () => {
document.head.removeChild(script);
};
}
}, []);
if (typeof window !== 'undefined' && !scriptLoaded) {
return null;
}
// const TELEGRAM_SRC = 'https://telegram.org/js/telegram-web-app.js';

// const [scriptLoaded, setScriptLoaded] = useState(false);

// useEffect(() => {
// if (typeof window !== 'undefined' && typeof location !== 'undefined') {
// const script = document.createElement('script');
// script.src = TELEGRAM_SRC;
// script.type = 'text/javascript';
// script.onload = () => {
// setScriptLoaded(true);
// };

// script.onerror = () => {
// console.error('Failed to load the Telegram script');
// setScriptLoaded(false);
// };
// document.head.appendChild(script);
// return () => {
// document.head.removeChild(script);
// };
// }
// }, []);
// if (typeof window !== 'undefined' && !scriptLoaded) {
// return null;
// }

return (
<CommonErrorBoundary>
Expand Down

0 comments on commit 76090a8

Please sign in to comment.