Skip to content

Commit

Permalink
Fixed conditional rendering of login button (#28)
Browse files Browse the repository at this point in the history
* Fix conditional rendering of login button

* Update config and lockfile

* Add changelog
  • Loading branch information
manzoorwanijk authored Aug 31, 2024
1 parent 5016b0f commit d84bbd2
Show file tree
Hide file tree
Showing 4 changed files with 7,366 additions and 5,818 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-buttons-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@telegram-auth/react": patch
---

Fixed conditional rendering of login button
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dev": "turbo run dev --parallel",
"kick-off": "pnpm clean && pnpm build:p",
"lint": "eslint \"{packages,examples,internal}/**/*.{ts,tsx,js,jsx,json}\"",
"lint:fix": "pnpm run lint -- --fix",
"lint:fix": "pnpm run lint --fix",
"release": "changeset publish",
"release:dev": "changeset publish --tag dev",
"test": "turbo run test",
Expand Down
16 changes: 16 additions & 0 deletions packages/react/src/LoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ export function LoginButton(props: LoginButtonProps) {

// add the script element to the DOM
hiddenDivRef.current?.after(scriptRef.current);

// Save siblings before unmount
const siblings = hiddenDivRef.current?.parentElement?.children || [];

return () => {
// destroy the script element on unmount
scriptRef.current?.remove();

// We also need to remove the rendered iframe
for (const element of siblings) {
if (element instanceof HTMLIFrameElement && element.src.includes('oauth.telegram.org')) {
element.remove();
break;
}
}
};
}, [props]);

return <div ref={hiddenDivRef} hidden />;
Expand Down
Loading

0 comments on commit d84bbd2

Please sign in to comment.