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

Standardize extraction of account id and page id from route #456

Merged
merged 20 commits into from
Apr 5, 2022

Conversation

kachkaev
Copy link
Contributor

@kachkaev kachkaev commented Apr 1, 2022

🌟 What is the purpose of this PR?

This PR provides an alternative solution to #456. It prevents account id from being undefined during SSR by not rendering app pages on the server. Frontend page files are converted to kebab-case given the opportunity.

🔍 What does this change?

  • New hooks: useRouteAccountInfo and useRoutePageInfo (inspired by CurrentWorkspaceContext)

  • Replacement of all router.query["pageId|accountId"] with new hooks. This improves type-safety and provides future-proofing. Using slugs instead of ids should be easier now.

  • Page files were renamed [account-slug] and [page-slug] instead of [accountId] and [pageId]

  • _app.page.ts is updated: server-side rendering is skipped because page and account ids are undefined and this may crash some components

    App UI often depends on [account-slug] and other query params. However, router.query is empty during server-side rendering for pages that don’t use getServerSideProps. By showing app skeleton on the server, we avoid UI mismatches during rehydration

  • kebab-case is enforced for "[frontend]/src/pages/**/*" to speed-up future reviews. Related to Configure ESLint rules for shared folders, bump ESLint deps  #453

⚠️ Known issues

  • Current ‘app skeleton’ is null. We should replace it with Hash logo or some loader. Alternatively, we can consider making all /[account-slug]/* pages server-rendered by adding getServerSideProps. However, this will significantly increase server load and create some additional edge cases for UI layouts.

🐾 Next steps

  • Continue working on UI components for the entity editor

  • Consider parsing [account-slug] and converting it to accountId inside RouteAccountInfoProvider

🔗 Related links

🛡 What tests cover this?

  • Playwright, unit
  • Manual

❓ How to test this?

  1. Checkout the branch / view the deployment
  2. Open account home page
  3. Navigate between a few pages
  4. Navigate to a page for a type and observe that the list of pages is still there.

@github-actions github-actions bot added area/apps > hash* Affects HASH (a `hash-*` app) frontend labels Apr 1, 2022
@kachkaev kachkaev marked this pull request as ready for review April 1, 2022 11:48
@kachkaev kachkaev marked this pull request as draft April 1, 2022 11:48
@vercel vercel bot temporarily deployed to Preview – hash April 4, 2022 19:30 Inactive
@github-actions github-actions bot added playwright and removed area/deps Relates to third-party dependencies (area) labels Apr 4, 2022
@kachkaev kachkaev changed the title Switch to kebab-case in frontend pages Standardise extraction of account id and page id from route Apr 4, 2022
@@ -16,7 +16,7 @@ import { useCreatePage } from "../../../hooks/useCreatePage";

type AccountPageListProps = {
accountId: string;
currentPageEntityId: string;
currentPageEntityId?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@teenoh I’ve made this parameter optional so that we can see the list of pages even if we browse a type. This behavior feels more logical to me, but I’m happy to change it back if the spec suggests otherwise.

Comment on lines +41 to +44
export interface UseRouteAccountInfo {
(options: { allowUndefined: true }): RouteAccountInfo | undefined;
(options?: { allowUndefined?: false }): RouteAccountInfo;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@teenoh this gives us extra type safety when we use the hook. We don’t need ! as discussed in #460 (comment)

@@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";

test("guest user navigation to login and signup pages", async ({ page }) => {
await page.goto("/");
await page.waitForNavigation({ url: "**/login" });
await page.waitForURL("**/login");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

waitForNavigation failed for me in CI, so I investigated it and found the fix. Unlike waitForNavigation, waitForURL succeeds even if we are on the right page already. Not sure if I have fixed some general test flakiness by this or this was a new glitch. It might be related to a change in _app.page.tsx.

@kachkaev kachkaev requested a review from teenoh April 4, 2022 20:17
@kachkaev kachkaev marked this pull request as ready for review April 4, 2022 20:17
@kachkaev kachkaev changed the title Standardise extraction of account id and page id from route Standardize extraction of account id and page id from route Apr 4, 2022
Copy link
Contributor

@teenoh teenoh left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @kachkaev

@vercel vercel bot temporarily deployed to Preview – hash April 5, 2022 09:02 Inactive
@kachkaev kachkaev enabled auto-merge (squash) April 5, 2022 09:02
@kachkaev kachkaev merged commit eeaca0e into main Apr 5, 2022
@kachkaev kachkaev deleted the ak/kebab-case-in-pages branch April 5, 2022 09:08
@vilkinsons vilkinsons added type/eng > frontend Owned by the @frontend team area/tests > playwright New or updated Playwright tests and removed area: frontend labels Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apps > hash* Affects HASH (a `hash-*` app) area/tests > playwright New or updated Playwright tests type/eng > frontend Owned by the @frontend team
Development

Successfully merging this pull request may close these issues.

None yet

3 participants