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

feat: new create pages to use new defineRouter #963

Merged
merged 7 commits into from
Nov 10, 2024

Conversation

tylersayshi
Copy link
Contributor

@tylersayshi tylersayshi commented Oct 12, 2024

This adds a new version of createPages to use new_defineRouter as new_createPages

Copy link

vercel bot commented Oct 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
waku ⬜️ Ignored (Inspect) Visit Preview Nov 10, 2024 4:08am

@tylersayshi
Copy link
Contributor Author

I'm working on replacing the structures here: https://github.com/dai-shi/waku/blob/main/packages/waku/src/router/create-pages.ts#L190-L205

with a lookup that will be from path to components for that path like is done here: https://github.com/dai-shi/waku/blob/main/examples/22_define-router/src/entries.tsx#L66-L87

Initially I thought this would be good to do after, but as I am seeing the new defineEntries style it seems clear that changing these structures first will be the best approach.

Copy link

codesandbox-ci bot commented Oct 18, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

sorry for the delay.

packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
@tylersayshi
Copy link
Contributor Author

renderRoute is in a place where I am ready to test it

I need to work on getPathConfig to fix this comment now: #963 (comment)

I'll follow up here after fixing getPathConfig then digging into running and tested everything :)

@tylersayshi
Copy link
Contributor Author

tylersayshi commented Oct 30, 2024

@dai-shi if this code had a layout at /bar/_layout.tsx https://github.com/dai-shi/waku/blob/main/examples/22_define-router/src/entries.tsx#L34-L43

would it change to the following?

      {
        pattern: '/bar',
        path: [{ type: 'literal', name: 'bar' }],
        components: {
          'route:/bar': { isStatic: true },
          root: { isStatic: true },
          'layout:/': { isStatic: true },
          'layout:/bar': { isStatic: true },
          'page:/bar': { isStatic: true },
        },
      },

@tylersayshi

This comment was marked as outdated.

@tylersayshi
Copy link
Contributor Author

Should the other examples be moved to new_createPages as well with this PR?

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

So, I find it very difficult to prove correctness, mainly due to the lack of tests (my bad) for static/dynamic component behavior.
Let me play with it and see if I can find anything.

packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
@dai-shi
Copy link
Owner

dai-shi commented Nov 5, 2024

If we made this change,

diff --git a/examples/21_create-pages/src/components/NestedBazPage.tsx b/examples/21_create-pages/src/components/NestedBazPage.tsx
index ed7488f7..96f6ddd1 100644
--- a/examples/21_create-pages/src/components/NestedBazPage.tsx
+++ b/examples/21_create-pages/src/components/NestedBazPage.tsx
@@ -2,6 +2,7 @@ const Baz = () => (
   <div>
     <h2>Nested</h2>
     <h3>Baz</h3>
+    <p>{new Date().toISOString()}</p>
   </div>
 );
 
diff --git a/examples/21_create-pages/src/entries.tsx b/examples/21_create-pages/src/entries.tsx
index e214e5a4..9dcdbe81 100644
--- a/examples/21_create-pages/src/entries.tsx
+++ b/examples/21_create-pages/src/entries.tsx
@@ -48,7 +48,7 @@ const pages = new_createPages(
     }),
 
     createPage({
-      render: 'static',
+      render: 'dynamic',
       path: '/nested/baz',
       component: NestedBazPage,
     }),

we should see the latest date, but it's not.

I haven't looked into it wether the issue is in new_defineRouter and/or new_createPages.

@tylersayshi
Copy link
Contributor Author

So, I find it very difficult to prove correctness, mainly due to the lack of tests (my bad) for static/dynamic component behavior. Let me play with it and see if I can find anything.

Changing the other createPages examples over to new_createPages should help test things a bit, right?

I can add a test for the date bug you mentioned as well though.

@tylersayshi
Copy link
Contributor Author

we should see the latest date, but it's not.

I haven't looked into it wether the issue is in new_defineRouter and/or new_createPages.

hmmm did you run pnpm -F waku compile?

It seems like it's updating for me

Screen.Recording.2024-11-05.at.10.52.39.PM.mov

pretty sure this is the same diff but pasting to be 1000% sure haha

 !  ~/gitspace/waku   new-create-pages    git diff                                                                                     3m
diff --git a/examples/21_create-pages/src/components/NestedBazPage.tsx b/examples/21_create-pages/src/components/NestedBazPage.tsx
index ed7488f..96f6ddd 100644
--- a/examples/21_create-pages/src/components/NestedBazPage.tsx
+++ b/examples/21_create-pages/src/components/NestedBazPage.tsx
@@ -2,6 +2,7 @@ const Baz = () => (
   <div>
     <h2>Nested</h2>
     <h3>Baz</h3>
+    <p>{new Date().toISOString()}</p>
   </div>
 );
 
diff --git a/examples/21_create-pages/src/entries.tsx b/examples/21_create-pages/src/entries.tsx
index e214e5a..9dcdbe8 100644
--- a/examples/21_create-pages/src/entries.tsx
+++ b/examples/21_create-pages/src/entries.tsx
@@ -48,7 +48,7 @@ const pages = new_createPages(
     }),
 
     createPage({
-      render: 'static',
+      render: 'dynamic',
       path: '/nested/baz',
       component: NestedBazPage,
     }),

@dai-shi
Copy link
Owner

dai-shi commented Nov 6, 2024

It seems like it's updating for me

I'm sorry, it was about when we do client navigation. Like, clicking "Home" and then clicking "Nested / Baz".

@dai-shi
Copy link
Owner

dai-shi commented Nov 6, 2024

This is how it works with the current main.

Screen.Recording.2024-11-06.at.20.42.12.mov

@tylersayshi
Copy link
Contributor Author

unsure if this fix is the best way to fix the issue, but the issue with nested/baz not re-rendering on client side navigation was because NewRouter was cacheing the path

5f927b6

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

element.isStatic should only be about the element.

packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
packages/waku/src/router/create-pages.ts Outdated Show resolved Hide resolved
@dai-shi dai-shi merged commit ae703c1 into dai-shi:main Nov 10, 2024
26 checks passed
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