-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
load function not working #911
Comments
Not sure why the bare input isn't working yet, but using the |
Ok, that fixes it, but the data still jumps: https://analog-test-mu.vercel.app/ https://github.com/jdgamble555/analog-test/blob/master/src/app/pages/index.page.ts I'm trying to figure out where the state transfer takes place on this. J |
I see. It happens here https://github.com/analogjs/analog/blob/main/packages/router/src/lib/route-config.ts#L51-L56 HttpClient isn't used during prerendering though, as it's a direct API request. |
Is there some other way to detect its using edge rendering at build time than the |
I think if you visit a non-prerendered page and use SSR it should work correctly. You can also skip prerendering of the analog({
prerender: {
routes: []
}
}) |
Ok got it! https://analog-test-mu.vercel.app/ So it was prerendering thing. I would think that should be disabled by default as most front pages are going to be dynamic? J |
We discussed this previously and most sites building with Analog would prerender the root URL unless using something like tRPC https://analogjs.org/docs/features/server/server-side-rendering#prerendering-routes |
@brandonroberts - I've been thinking more about this. I think the I updating an old article on preloading data in angular universal to show how this is done now-a-days. REPO: GitHub Maybe the core code of Analog should work this way. This is how SvelteKit, Nuxt, Next, etc would do it. @brandonroberts what are your thoughts? J |
@brandonroberts - Just wanted to give you an example of the resolver version:
The component will not load until the data is resolved. If you use an observable (toSignal is best), and you have data that could change, you could easily convert it for child routes etc. and the data will get updated by the observable. https://angular-17-todo.vercel.app/ So in Analog's case, you could:
All of this under-the-hood. Some ideas... either way, I firmly believe the J |
@jdgamble555 we're missing the CSRF/cache part, but this is also what the 1/2. "load" resolver for the route
You can also define a resolver in the // about.page.ts
export const routeMeta: RouteMeta = {
resolve: {
load: LoadResolver
}
};
@Component({...})
export default class AboutComponent {
data = toSignal(injectLoad(), { requireSync: true });
} We could make this work for manually configured routes also. I agree a resolver works for both here though |
No I figured that's how it works, but you could probably simplify the code with a resolver. Does your code refetch on the browser after the server loads? I forgot that the Side Note: It looks like this is how SvelteKit is getting the URL on the server so you could avoid the ENV variable. (I'm not understanding why you have it). J |
Closing in favor of this: |
Please provide the environment you discovered this bug in.
I'm following the directions:
https://analogjs.org/docs/features/data-fetching/server-side-data-fetching
And I get an undefined error in both dev and prod.
Which area/package is the issue in?
vite-plugin-angular
Description
ERROR TypeError: Cannot read properties of undefined (reading 'loaded')
Please provide the exception or error you saw
Other information
I want the variable to load on the server, not get hydrated and then updated either way. I would also think the load function would use a resolver?
Here is the affected pages:
https://github.com/jdgamble555/analog-test/tree/master/src/app/pages
Trying to figure out Analog for the first time :)
J
I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: