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

Sveltekit framework support #391

Closed
fblan opened this issue Jun 21, 2023 · 19 comments · Fixed by #393 or #401
Closed

Sveltekit framework support #391

fblan opened this issue Jun 21, 2023 · 19 comments · Fixed by #393 or #401
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@fblan
Copy link
Contributor

fblan commented Jun 21, 2023

Describe the bug

Hi,
I have implemented quarkus quinoa with a sveltekit application that is using vite.
In production mode, everything is working perfectly, but I am not able to make it work in dev mode.

If I put properties:

quarkus.quinoa.dev-server=true
%dev.quarkus.quinoa.index-page=/

I have the following error in console :

Error: Not found: //
at resolve (C:/DEV/snipets/sveltekit-quark/230621-svk3/src/main/webui/node_modules/@sveltejs/kit/src/runtime/server/respond.js:430:13)

and I am redirected to quarkus default index.html.

If don't have %dev.quarkus.quinoa.index-page=/ , I have the following error:

Error: Not found: /index.html                                                                                                                                                                                                       
    at resolve (C:/DEV/snipets/sveltekit-quark/230621-svk3/src/main/webui/node_modules/@sveltejs/kit/src/runtime/server/respond.js:430:13)

As a workaround, I have tried to put sev-server to false but in this case the problem is that sveltekit generate some files in a sveltekit folder in sources during code generation, and these files are deteted by live reload. The compilation is continuously trigered.

I hope I didn't make a mistake, and thanx a lot for your work, this extension is very cool :)

Quinoa version

2.0.5

Quarkus version

3.1.2.Final

Build / Runtime

Vite

Package Manager

None

Steps to reproduce the behavior

clone https://github.com/fblan/test-quark/tree/main
./mvnw package
java -jar target/quarkus-app/quarkus-run.jar
open browser on http://localhost:8080
the application is displayed normally.
click on SVPOSTS and a page is displayed. This page call quarkus rest api. Everything is working perfectly.

start the dev mode:
`
Error: Not found: //
at resolve (C:/DEV/snipets/sveltekit-quark/230621-svk3/src/main/webui/node_modules/@sveltejs/kit/src/runtime/server/respond.js:430:13)

`

Expected behavior

same behavior than in production mode.

@melloware
Copy link
Contributor

Yep definitely something whacky here how SvelteKit works. I will look into it

@melloware
Copy link
Contributor

Can you elaborate on sev-server to false? I would like to try this. I think we need to add .svelte-kit to..

private static final Set<String> IGNORE_WATCH = Set.of("node_modules", "build", "target", "dist", "out");

@fblan
Copy link
Contributor Author

fblan commented Jun 22, 2023

Svelte kit use .svelte-kit folder to do some preprocessing.
I finally was able to change ".svelte-kit" it to "out" (thanx for the information) directory, and this modification enable the dev server false to work!
(the link to the repo is : https://github.com/fblan/test-quark/tree/devserver/false )
Perhaps if IGNORE_WATCH was configurable, it would be a nice to have.
I will try to investigate on the dev-server true part this evening.

@ia3andy
Copy link
Collaborator

ia3andy commented Jun 22, 2023

Svelte kit use .svelte-kit folder to do some preprocessing. I finally was able to change ".svelte-kit" it to "out" (thanx for the information) directory, and this modification enable the dev server false to work! (the link to the repo is : https://github.com/fblan/test-quark/tree/devserver/false ) Perhaps if IGNORE_WATCH was configurable, it would be a nice to have. I will try to investigate on the dev-server true part this evening.

I think it makes sense to have quarkus.quinoa.classic-dev.ignore-dirs. I've thought about classic-dev opposed to dev-server, but if you have a better idea go for it. Having a specific namespace is important as it will allow new possible options in the future without breaking the api.

@fblan Ready for another great contribution :)?

@ia3andy
Copy link
Collaborator

ia3andy commented Jun 22, 2023

Not sure why the dev-server mode isn't working, is it due to svelte?

@melloware
Copy link
Contributor

@ia3andy it looks like this SVK does some crazy stuff with dynamically generating the initial JS file that it loads on /. I have never seen anything like it. I think we definitely need to try and make this work out of the box.

I personally think we should ignore all "." Directories as I realized ".next" also gets generated when using NextJS

@ia3andy
Copy link
Collaborator

ia3andy commented Jun 22, 2023

@ia3andy it looks like this SVK does some crazy stuff with dynamically generating the initial JS file that it loads on /. I have never seen anything like it. I think we definitely need to try and make this work out of the box.

I personally think we should ignore all "." Directories as I realized ".next" also gets generated when using NextJS

Yeah, ok that makes sense we can give it a try .* and act if there are issues in the future 👍

@melloware melloware self-assigned this Jun 22, 2023
@melloware melloware added the bug Something isn't working label Jun 22, 2023
@melloware melloware added this to the 2.0.6 milestone Jun 22, 2023
@melloware
Copy link
Contributor

melloware commented Jun 22, 2023

@fblan need some help here. Can you paste here your EXACT Quinoa settings? I still can't get this to work in either Dev mode or Production mode?

I am using an out of the box Svelte Kit hello world app.

@fblan
Copy link
Contributor Author

fblan commented Jun 22, 2023

To have it working in production mode:
if sveltekit you have to change sveltekit configuration:
you must install static adapter:
in webui folder:
npm i -D @sveltejs/adapter-static,

then in svelte.config.js:

import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/kit/vite';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	preprocess: vitePreprocess(),
	kit: {
		adapter: adapter({
            fallback: 'index.html' // may differ from host to host
        })
	}
};

export default config;

and in package.json you have to add the start script:
"start": "vite dev"

With this, the production mode should work.
If it is not the case don't hesitate!

@melloware
Copy link
Contributor

Sorry what about your Quinoa props?

quarkus.quinoa.dev-server=false
quarkus.quinoa.build-dir=.svelte-kit/output
quarkus.quinoa.index-page=/
#quarkus.quinoa.enable-spa-routing=false

???

@fblan
Copy link
Contributor Author

fblan commented Jun 22, 2023

sorry I miss read:

quarkus.quinoa.package-manager-install=true
quarkus.quinoa.package-manager-install.node-version=18.16.0
quarkus.quinoa.build-dir=build
quarkus.quinoa.enable-spa-routing=true
quarkus.quinoa.dev-server=false
quarkus.quinoa.index-page=index.html

@fblan
Copy link
Contributor Author

fblan commented Jun 22, 2023

It is strange, I have tried with quinoa 2.0.5 and dev-server=false works well, but when I try with last snapshot version it is not working anymore. I will try to see why.

@melloware
Copy link
Contributor

I am investigating

@melloware
Copy link
Contributor

OK submitted a PR that adds Svelte instructions I was able to test them myself and boil them down to minimal changes.

However if you use Svelte's alternative using Vite it works out of the box with Quinoa including Hot Swapping dev mode!

See: https://svelte.dev/docs/introduction#start-a-new-project-alternatives-to-sveltekit

@melloware melloware changed the title Quarkus dev mode quinoa + sveltekit not working Sveltekit support Jun 23, 2023
@melloware melloware changed the title Sveltekit support Sveltekit framework support Jun 23, 2023
@melloware melloware added enhancement New feature or request and removed bug Something isn't working labels Jun 23, 2023
@fblan
Copy link
Contributor Author

fblan commented Jun 23, 2023

First of all, thanx a lot for the integration of sveltekit : 👍

I have another question : I have tried to make quinoa work with sveltekit in devserver mode.
I faced 3 problems:

  1. vite wait in root url in dev mode while it wait on index.html in normal mode
  2. sveltekit use weird internals link in dev mode for parameterized pages like /src/generated/[param]/+page.ts and these link are not accepted by vertx.
  3. on quarkus restart in dev mode, it is not able to connect anymore to vite server (connection refused).

I was able to overcome the two first issues:

First issue:

  • setting dev index-page to '/':
    %dev.quarkus.quinoa.index-page=/
  • by correcting one class in QuinoaDevProxyHandler function handle line 60, replacing
- final String resourcePath = path.endsWith("/") ? path + config.indexPage : path;
+ final String resourcePath = path.endsWith("/") && !"/".equals(config.indexPage) ? path + config.indexPage : path;

Second issue:
and by adding in jvm parameters when I start quarkus:
-Dvertx.disableURIValidation=true

But I am struggling for now with the third issue.
I think the correction of QuinoaDevProxyhandler should not hurt (but I am not totally sure :) )

What do you think?

@melloware
Copy link
Contributor

Feel free to submit a PR!

@melloware
Copy link
Contributor

Also if you want to try it here is a Svelte example that works out of the box including Dev mode.

vite-svelte.zip

@fblan
Copy link
Contributor Author

fblan commented Jun 23, 2023

I will have look, thanx again.
I will do a PR on monday.

Thanx a lot for your help :)

@ia3andy
Copy link
Collaborator

ia3andy commented Jun 26, 2023

@fblan

First of all, thanx a lot for the integration of sveltekit : 👍

I have another question : I have tried to make quinoa work with sveltekit in devserver mode. I faced 3 problems:

  1. vite wait in root url in dev mode while it wait on index.html in normal mode
  2. sveltekit use weird internals link in dev mode for parameterized pages like /src/generated/[param]/+page.ts and these link are not accepted by vertx.
  3. on quarkus restart in dev mode, it is not able to connect anymore to vite server (connection refused).

I was able to overcome the two first issues:

First issue:

  • setting dev index-page to '/':
    %dev.quarkus.quinoa.index-page=/
  • by correcting one class in QuinoaDevProxyHandler function handle line 60, replacing
- final String resourcePath = path.endsWith("/") ? path + config.indexPage : path;
+ final String resourcePath = path.endsWith("/") && !"/".equals(config.indexPage) ? path + config.indexPage : path;

This seems like a good fix to add.

Second issue: and by adding in jvm parameters when I start quarkus: -Dvertx.disableURIValidation=true

I think we should request to create a configuration in Quarkus Vertx for this. So you may configure something like this:

%dev.quarkus.vertx.disable-uri-validation=true

But I am struggling for now with the third issue. I think the correction of QuinoaDevProxyhandler should not hurt (but I am not totally sure :) )

What do you think?

For the connection refused, have you tried the latest version (I added a fix recently for "connection refused")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants