Skip to content
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

Code style #8

Merged
merged 7 commits into from
Sep 18, 2023
Merged

Code style #8

merged 7 commits into from
Sep 18, 2023

Conversation

hubsmoke
Copy link
Member

@hubsmoke hubsmoke commented Sep 15, 2023

changes to code organization for frontend components. use 'use client' directive to ensure non-server components aren't rendered on server

contains all changes in #7

this is separate from #7 in case you disagree with the code styling but still want the fixes in 7

Copy link
Collaborator

@m0ar m0ar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soolid cleanup, much appreciated 🏆 🧁

await getProfile();
};

const getProfile = useCallback(async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the docs on useCallback but still not clear, can you elaborate on what this in combination with the useEffect dependency achieves?

Copy link
Member Author

@hubsmoke hubsmoke Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so useEffect handler will potentially not trigger on relevant state changes (which can sometimes look like the component is operating on stale data) if you don't pass a dependency array listing all outside variables being used inside the useEffect. So if previously a useEffect did not have the getProfile set, then either the variables the getProfile reads could be stale or there could excessive re-renders and they may not be stale (I think it depends on the component, but it could be one or the other, need to test more). So you need to pass in [getProfile] to useEffect if you want to use it without excessive re-renders and with updated data.

The problem then is that getProfile will be updated on every render and trigger the useEffect unless you wrap it in useCallback, so we need to wrap the function in useCallback and attach a dependency array that ONLY updates the getProfile function when a listed dependency changes @m0ar

I think in this particular case with getProfile only triggering on useEffect on startup, the change may be almost nothing. In the previous case if composeClient or ceramic.did update we may have no re-render, in the new case I believe a re-render would trigger. We may be able to revert this if getProfile is working as expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent explanation, thanks @hubsmoke 🧁

This is probably the reason behind several things that are a bit odd in the app now, good catch :)

"models": []
}
}
{"anchor":{},"http-api":{"cors-allowed-origins":[".*"],"admin-dids":["did:key:z6Mkewm16NferyW66tYVrSvfUeJHFxtVzbRjjrMgEKxYq5qw"]},"ipfs":{"mode":"bundled"},"logger":{"log-level":2,"log-to-files":true,"log-directory":"local-data/ceramic/logs"},"metrics":{"metrics-exporter-enabled":false,"metrics-port":9090},"network":{"name":"inmemory"},"node":{},"state-store":{"mode":"fs","local-directory":"local-data/ceramic/statestore"},"indexing":{"db":"sqlite:///Users/sinaiman/Dev/desci-composedb/local-data/ceramic/indexing.sqlite","allow-queries-before-historical-sync":true,"models":[]}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, like you pointed out in discord this shouldn't be checked in due to user-specific paths. Mind removing it with git rm?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: the reason for the absolute paths is that the indexing DB cannot handle relative ones

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a commit with this removed 👌

import { ComposeClient } from "@composedb/client";

import { definition } from "../src/__generated__/definition.js";
import { definition } from "@/src/__generated__/definition.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about this syntax, nice 💯

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can set it inside tsconfig.json
Screen Shot 2023-09-15 at 1 05 08 PM

Comment on lines +24 to +27
const handleLogin = useCallback(async () => {
await authenticateCeramic(ceramic, composeClient);
await setViewerId();
}, [ceramic, composeClient, setViewerId]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well, mind elaborating?

Comment on lines +17 to +19
"paths": {
"@/*": ["./*"]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@m0ar
Copy link
Collaborator

m0ar commented Sep 15, 2023

@hubsmoke another thought that popped up when I saw the vscode settings, in the future I wanna look into Husky for setting up commit hooks for linting/static analysis. If we aim to have OSS contributors we probably shouldn't rely on code style through the configuration of a single editor :)

@m0ar m0ar merged commit 5aafe5c into main Sep 18, 2023
@m0ar m0ar deleted the code-style branch September 18, 2023 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants