-
Notifications
You must be signed in to change notification settings - Fork 373
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
[Bug?]: undefined userRouteData
when using jsx instead of tsx
#1004
Comments
Is ssr enabled? Tried the sample out and noticed that with ssr disabled Otherwise can't reproduce it. |
This is actually a question I'm a bit unsure:
export default defineConfig({
plugins: [
unocssPlugin(),
unocss(),
{
...(
mdx({
jsxImportSource: "solid-js",
jsx: true,
providerImportSource: "solid-mdx",
rehypePlugins: [rehypeHighlight, remarkGfm],
})
//
),
enforce: "pre",
},
solid({
adapter: (await import("solid-start-static")).default(),
extensions: [".mdx", ".md"],
ssr: true,
}),
],
ssr: {
external: ["ag-grid-solid"],
},
}); |
Should be on. meta.env.SSR is always false or I have never seen it set to true. START_SSR is what to look for. |
Here you go: In the |
|
Sorry for my ignorance... So I put the Questions from my confusion of the document:
|
The route where your component is in. In your case
|
OK, I tried to understand the concept “route”… I thought any file inside
the ‘route’ folder is a route, but it seems it is not… is it the file that
renders a page a “route”?
So the ‘student.tsx’ file actually renders a page?
In my case, even the ‘schedule.jsx’ export html things, but since it is
used in the index.jsx, the file is actually a component, and only the
‘index.jsx’ is a ‘route’?
Any route file must be inside the “routes”folder, but files inside the
‘routes’ folder may not be a route (if it is not rendered as a page)?
…On Tue, Aug 15, 2023 at 22:29, Davide ***@***.***> wrote:
The route where your component is in. In your case
routes/(index)/index.jsx.
1. No, the router handles routeData, you only need to access it with
useRouteData. (It either uses a context underneath or something similar.
Not sure about the implementation)
2. I belive this only applies to nested routes
<https://start.solidjs.com/core-concepts/routing#nested-routes> where
you could end up with two exports stacked.
- Layout (export routeData)
- Page (export routeData)
- Componente (useRouteData) : Will not get the routeData from
Layout
—
Reply to this email directly, view it on GitHub
<#1004 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOVGVQRCPJDQKBM6QH56WTXVPL2ZANCNFSM6AAAAAA3Q23LBM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I am sorry if I caused any confusion.
You lost me a bit here. Files placed under /src/routes are treated as routes as stated in the docs. For files placed in the routes directory the following things will be picked up when generating the routes:
It is possible to have a default export and export functions named like HTTP method at the same time. With the exception of default export and GET method where only one or the other is possible. // This is returned on a POST request to this route
export function POST() {
return new Response('API response');
}
export default function Home() {
return <div>Page</div>
} You can still export other stuff and import it somewhere else but it will not be used when generating the route. To come back to the initial issue with routeData. Here is an example with useRouteData inside the ClientOnlySchedule component. routes/(index)/index.jsx // since ag-grid has no SSR feature, make it client-only
import { clientOnly } from "~/utils";
export function routeData() {
return createRouteData(async () => {
const response = await fetch("/schedule.json");
return await response.json();
});
}
const ClientOnlySchedule = clientOnly(() =>
import("~/schedule.jsx")
);
function Home() {
...
} src/schedule.jsx function Schedule() {
const scheduleData = useRouteData();
...
} |
This is what I initially understand and I created a And you pointed to me that That's where I got confused that if all files under But anyway, I did as you suggested, put the if I do (from the doc)
If I do (in your code)
The return value of The test Repo is updated: https://github.com/xarthurx/ddmTestRepo |
Opened a PR on your repo fixing something else. Should work on dev and build. Left also some comments. Simpler than pasting everything here. I could not reproduce the error in the image. It just showed an empty table in dev and the "schedule not loaded successfully..." in build. If the PR does not work for you then there is maybe something else wrong.
I should have been more specific. What I meant was that the the routeData function is a feature ot the router and has to be exported from the route file that uses your component. |
Now it works!
I see, now I understand totally. Really really appreciate your help!!! |
Duplicates
Latest version
Current behavior 😯
routeData
approach of hosting data on the server.jsx
instead oftsx
.When using the example:
And transfer it to
jsx
:my console always report
useRouteData()
is undefined.I'm not sure if this is a bug or my misuse, but I cannot find any info on how to use it in jsx.
Expected behavior 🤔
no errors.
Steps to reproduce 🕹
Steps:
Context 🔦
No response
Your environment 🌎
No response
The text was updated successfully, but these errors were encountered: