-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Pages using shadow endpoints do not render until all data is loaded #4458
Comments
This is functioning as intended. Anything in |
onMount works fine with most calls, but when importing 'oracledb' or 'pg', therein lies the problem I was hoping Shadow Endpoints would resolve, which it does except the delayed rendering of page. Let's say I use onMount and call the js file that successfully queries the database and returns the data, and then start Sveltekit up using npm run dev - when that page loads it will now give a Vite error about "process is not defined" 500 And below is a .svelte file which has some extraneous html to show what I've tried to have this data display with onMount. This .svelte file fails to get the data from the js file that works fine without sveltekit.
There are dozens of pages on hacky workarounds related to this and Sveltekit that did not work for me. Just for example: But I still get this error with sveltekit and oracledb. I can do npm run build and npm run preview and seems to not give that error, but then gives an error about package.json. Would prefer just seeing this work on npm run dev and doing database calls from Sveltekit. @Conduitry have you been able to do a database call to Oracle or Postgres from Sveltekit or have a clear example of how that is done? Maybe I am heading in the wrong direction, and this should be moved over to Discussion. I read the Vite FAQs and the Svelte FAQs on Vite but something seems to be missing. I could also go back to just using Server to return the database query responses, but this would be much cooler to do something straight from Sveltekit. |
I'll just create another page that will fetch from the Sveltekit endpoint page via |
You just need two files: a page and a standalone endpoint. |
@mrkishi are you sure about that when doing database calls from Sveltekit? A page and a standalone works fine for API calls, but when attempting to use a module that connects to a db like oracledb or pg, Vite gives an error about process is not defined. You can do two pages, if you are fine that the page will wait to render until the data is loaded, but if you want to render the page that isn't just a browser loading until the query response is returned, then it seems you need at least 3 files for Sveltekit in your /routes folder. Maybe you can provide an example, because from what I encountered, a page and endpoint will either not render in your browser until all db data responses occur, or give a Vite error using npm run dev. |
I see, I put a function in the .js file that connects, queries, and then returns the content in JSON, then a .svelte file with different name to fetch the data from that url since there is no other .svelte file with same name. Thanks, glad I figured that out. |
Describe the bug
A page using (shadow) endpoints won't render until the data is returned. This is an issue in cases where for example a database call takes over 10 seconds, and to a user would appear to just be a site failing. This issue refers to using shadow endpoints as described in this solution #3532
I made an assumption I could merely use an #await block to display the data but the page will still not render anything until all data loaded for that particular component is returned even if other components are on the page. This may not be an issue if data being returned fast, but if you have a database call that takes > 10 seconds or multiple database calls, then the page will be in that load state until data is loaded. I describe how I made this work here #4456 and hopeful to use this, but soon came to realize this puts a wrench in database calls. While this design may have been to do just that, prevent any loading or flicker, I think an option to enable rendering before data is loaded would make this functionality more flexible.
Additionally, if you have multiple pages open, this cascades into each page waiting to load before it tries to run the query for the next page.
Perhaps there is a better way to do this that someone can point out, it's not clear to me from the Sveltekit docs.
Reproduction
The flow is the following: queryDatabase.js > data-result.js > data-result.svelte
First the js file which calls the database and receives data query-database.js
then the shadow endpoint data-result.js will return the body:
and finally the page that will not render anything until that data is retrieved which is the issue
Logs
No response
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: