I’m trying to add SSR to a routing module I’m working on in Bun.
I’d like the code to look something like this:
import Index from "./app/client/pages/Index";
import About from "./app/client/pages/About";
import { route, page } from "mypackage";
route.get("/", (context) => {
return page.render(<Index />);
});
route.get("/about/:name", (context) => {
return page.render(<About name={context.groups.name} />);
});
In the page render
function, I need to get the actual path to the react elements that were imported so that I can use Bun.build
to convert them to js, and also to hydrate them on the client side.
I cannot figure out how to get the path from the react element.
Here is what I’ve tried.
page render
:
export const render = (child: React.FC) => {
console.log(child);
require.resolve(child);
require.resolve(typeof child);
}
terminal output:
{
$$typeof: Symbol(react.transitional.element),
type: [Function: starDefault],
key: null,
props: {},
_owner: null,
ref: null,
_store: {
validated: 0,
},
_debugInfo: null,
}
error: Cannot find package "[object Object]" from "/Users/kejedi/Bun/framework/test.tsx"
Is this possible, or am I going to have to resolve it another way?
kejedi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.