-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional root rendering #213
Comments
I don't have a good idea about what's going wrong in your code. I don't think purely accessing the |
@Tao-VanJS From the profile, and some logging, I think that's what's happening. The profiler shows an unending series of the calls |
However, if I move the state and Firebase auth callback outside the component, it works as expected.
const authenticating = van.state(true);
const authenticated = van.state(false);
auth.onAuthStateChanged((user) => {
console.log(user)
if (user) authenticated.val = true;
else navigate(LOGIN_ROUTE);
authenticating.val = false;
});
export function AuthGuard(child: HTMLElement) {
if (authenticating.val || !authenticated.val) {
return div(
{ className: "w-full h-full grid place-items-center" },
Text({ align: "center" }, "Authenticating. Please wait...")
);
} else return child;
}
export default function App() {
return Router({
className: "w-screen h-screen",
routes: [
{ path: HOME_ROUTE, component: () => AuthGuard(HomePage()) },
{ path: LOGIN_ROUTE, component: LoginPage },
{ path: SIGNUP_ROUTE, component: SignupPage }
]
});
}
|
Can you try export function AuthGuard(child: HTMLElement) {
const authenticating = van.state(true);
const authenticated = van.state(false);
auth.onAuthStateChanged((user) => {
if (user) {
authenticated.val = true;
} else navigate(LOGIN_ROUTE);
authenticating.val = false;
});
return () => {
if (authenticating.val || !authenticated.val) {
return div(
{ className: "w-full h-full grid place-items-center" },
Text({ align: "center" }, "Authenticating. Please wait...")
);
} else return child;
}
}
export default function App() {
return Router({
className: "w-screen h-screen",
routes: [
{ path: HOME_ROUTE, component: AuthGuard(HomePage()) },
{ path: LOGIN_ROUTE, component: LoginPage },
{ path: SIGNUP_ROUTE, component: SignupPage }
]
});
} |
Unfortunately, this doesn't work since this calls the |
https://jsfiddle.net/Sirenko/jv29wexf/55/ Here's an example, + fixed a bug with the garbage collector for the HomePage (if there was reactivity on it, it would not work correctly after switching) |
I have this component which is supposed to show a loader while it checks the auth state and then, if authenticated, show the child.
The issue I run into is the tab freezes and from Chrome's tab manager, it just consumes memory at an exponential rate. I'm guessing using the
authenticated.val
in the function's body (and not in a derive or the content) causes an infinte binding.How do I resolve this?
The text was updated successfully, but these errors were encountered: