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

Redirects in "PageServerLoad" does result in 500 internal error within in a pnpm workspace if "preserveSymlinks" is used in vite.config.ts #12139

Open
msprada opened this issue Apr 19, 2024 · 0 comments

Comments

@msprada
Copy link

msprada commented Apr 19, 2024

Describe the bug

First of all I'm not 100% sure if this "defect" is caused by Vite or Svelte Kit. But I decided to go for a issue in the svelte kit repo. If this is related to Vite and the Svelte Kit Team cannot handle it, I will definitely open the ticket or transfer the ticket to the other Repo.

I search for similar bugs within the list and for sure within the www, but I could not find any ones.
Maybe it is related to this instance of Redirect Check wich was mentioned here => Redirects in load functions break when running client-side #5952

Situation:

  • I created a pnpm workspace including one application which provides a REST API (nestJS) and the second application which includes the svelte kit ui. Furthermore I have packages which includes all shared libraries e.g a lib for the dtos, models. etc.

To be able to reference the models library in the svelte application I added a symlink within the packages.json in the way pnpm wants it to be: "data-access-models": "workspace:*"

"dependencies":
 {
	"@lucia-auth/adapter-sqlite": "^3.0.1",
	"arctic": "^1.5.0",
	"better-sqlite3": "^9.5.0",
	"data-access-models": "workspace:*",
	"esm-env": "^1.0.0",
	"oslo": "^1.2.0"
},

So I can use this importing in my pages and components "page.svelte":

<script lang="ts"> import { OrderDto } from 'data-access-models'; export let data; const orders: OrderDto[] = data.orders; </script>

Without further changes with in the application this resulted in following error:

image

To get this working I had to change the vite.config extend the "resolve" part which results in following.


import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

export default defineConfig({
	plugins: [sveltekit()],
	test: {
		include: ['src/**/*.{test,spec}.{js,ts}']
	},
	resolve: {
		preserveSymlinks: true
	}
});

So far so could I could use the models and the component was rendered perfectly.

Currently I'm implementing authentication and authorization using Lucia Auth.

So there is the need of redirect a user from my homepage if he/she is not logged in.

So I included following file under routes folder "page.server.ts" and implementing the PageServerLoad Method.

export const load: PageServerLoad = async (event) => {
	if (!event.locals.user) {
		console.error('redirect triggered!');
		redirect(302, "/signin");
	}
	return {
		user: event.locals.user
	};
};

If I open my homepage within login into the application the ui shows me a 500 error instead of redirecting me to the /signin route.

Within my server logs I can see following entry:

image

And if navigating to the url /signin the Signin Screen is shown without any problems.

Reproduction

  • to reproduce the behavior visit Following Repo
  • it was newly created and only relevant part is included
  • follow the steps within in the readme.md file which is included in the root folder

Logs

No response

System Info

System:
    OS: macOS 11.7.10
    CPU: (8) x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
    Memory: 437.52 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 8.15.4 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 123.0.6312.124
    Safari: 16.6.1

Severity

blocking all usage of SvelteKit

Additional Information

If there is anything missing within the description please let me know.

@msprada msprada changed the title Redirects in "PageServerLoad" does result in 500 internal error within in a pnpm workspace if "preserveSymlinks" is used in site.config.ts Redirects in "PageServerLoad" does result in 500 internal error within in a pnpm workspace if "preserveSymlinks" is used in vite.config.ts Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant