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

(docs) Request for elaboration on usage docs for defineEntries #921

Open
tylersayshi opened this issue Sep 30, 2024 · 7 comments
Open

(docs) Request for elaboration on usage docs for defineEntries #921

tylersayshi opened this issue Sep 30, 2024 · 7 comments

Comments

@tylersayshi
Copy link
Contributor

tylersayshi commented Sep 30, 2024

defineEntries is a fn call to define how to render, build, and configure the ssr for your waku app.

Some initial usage docs live here: https://github.com/dai-shi/waku/blob/main/docs/minimal-api.mdx

It would be really helpful for someone new to look through how the initial usages of defineEntries are used, then summarize some info in a docs entry for this function.

@dai-shi dai-shi added the good first issue Good for newcomers label Sep 30, 2024
@ojj1123
Copy link
Contributor

ojj1123 commented Oct 1, 2024

I was wondering if you could explain where it is the explanation of defineEntries function in Docs or README! I couldn't find it since waku was released as v0.19.0. Is it deprecated

#24 (comment)

Oh I was also wondered defineEntries before releasing managed mode. If it's important to know this API for library authors, it's good to describe this API. Reading the source code of it briefly, It feels like it's working for build process. But it's too hard for newcomers to know about it.

const distEntries = await import(filePathToFileURL(distEntriesFile));

How about explain API descriptions like what each parameter work for or the interaction of parameters(renderEntries, getBuildConfig, getSsrConfig)? And then I feel like that it's easier to know and investigate the use cases of this API.

@rmarscher
Copy link
Contributor

rmarscher commented Nov 10, 2024

@dai-shi
Copy link
Owner

dai-shi commented Nov 11, 2024

We are in the middle of refactoring. defineEntries will be replaced with new_defineEntries soon-ish.

@dai-shi
Copy link
Owner

dai-shi commented Dec 13, 2024

@tylersayshi I'm not sure if this is a good first issue anymore.

@dai-shi dai-shi removed the good first issue Good for newcomers label Dec 13, 2024
dai-shi added a commit that referenced this issue Feb 6, 2025
#921 

`handleBuild` is very complicated.
@rmarscher
Copy link
Contributor

docs/minimal-api.mdx

To use React Server Components in Waku, you need to create an entries.tsx file in the project root directory and defineEntries to handle server requests.

If src/entries.tsx does not exist, the default uses the fsRouter from 'waku/router/server'. fsRouter returns a call to defineRouter which return a call to defineEntries.

handleRequest is passed an input object which contains the request as well as properties that vary depending on the "type" property. The possible "type" values on the input object are 'component', 'function', 'action' and 'custom'.

'component' is a server component render request. It is passed the rscPath and the rscParams.

'function' is a request to call a server function. It is passed the function args and it is passed the server function to call.

'action' --- I am not exactly sure what this is... but I think is it to render the HTML response via SSR after calling a server function that is part of a form action. If SSR (server-side rendering of HTML) is disabled, this returns null.

'custom' is a request to render HTML via SSR. If SSR is disabled, this returns null. A fallback HTML response must be provided for initial requests when SSR is disabled.

import { defineConfig } from 'waku/config';

export default defineConfig({
  middleware: () => [
    // context, dev-server and handler are the default middleware if not defined
    import('waku/middleware/context'),
    import('waku/middleware/dev-server'),
    import('waku/middleware/handler'),
    // fallback required if SSR is not enabled
    import('waku/middleware/fallback'),
  ],
});

The default handlers used by the router can be found in waku/router/define-router.

examples/12_nossr/src/entries.ts shows how it is possible to use defineEntries as middleware around the default fsRouter.

@dai-shi
Copy link
Owner

dai-shi commented Feb 6, 2025

Nice! Feel free to send a PR please.

I'm not sure if we should write about "router" and "managed mode" in minimal-api docs. Should there be another doc?

@rmarscher
Copy link
Contributor

rmarscher commented Feb 6, 2025

Nice! Feel free to send a PR please.

👍 I am backlogged, but I will get around it.

I'm not sure if we should write about "router" and "managed mode" in minimal-api docs. Should there be another doc?

Good idea to have another doc for managed mode and the filesystem router. The minimal-api docs can point out that managed mode is the default behavior and link to the other doc that explains.

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

No branches or pull requests

4 participants