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

PageData types don't update to reflect changes to load function(s) #5940

Closed
CaptainCodeman opened this issue Aug 16, 2022 · 12 comments · Fixed by #5974
Closed

PageData types don't update to reflect changes to load function(s) #5940

CaptainCodeman opened this issue Aug 16, 2022 · 12 comments · Fixed by #5974
Labels
bug Something isn't working
Milestone

Comments

@CaptainCodeman
Copy link
Contributor

Describe the bug

Having a +page.server.ts load function with no +page.ts load function results in PageData being any

Making changes to +page.ts load function means the PageData types lag and mismatch.

Reproduction

Just add and remove some static props to the load function return object.

Logs

No response

System Info

System:
    OS: macOS 12.5
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 1.56 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/local/bin/node
    npm: 8.3.1 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 102.1.39.111
    Chrome: 104.0.5112.79
    Chrome Canary: 106.0.5243.0
    Firefox: 103.0.2
    Safari: 15.6
    Safari Technology Preview: 16.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/kit: next => 1.0.0-next.411 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.8

Severity

annoyance

Additional Information

No response

@CaptainCodeman CaptainCodeman changed the title Page types still not working correctly PageData types don't update to reflect changes to load function(s) Aug 16, 2022
@dummdidumm
Copy link
Member

What do you mean by "lag" - as in, until you save the file?

@CaptainCodeman
Copy link
Contributor Author

CaptainCodeman commented Aug 16, 2022

As in, I save the file but the types don't update, they still show what it was, once. A full build is often needed to get it to see the source changes.

Screenshots to help explain it ...

Start with some type:
Screen Shot 2022-08-16 at 12 35 04 PM

Based on:
Screen Shot 2022-08-16 at 12 35 18 PM

Change it to:
Screen Shot 2022-08-16 at 12 35 27 PM

Types don't update to reflect changes:
Screen Shot 2022-08-16 at 12 35 37 PM

Server file (which I think are also missing):
Screen Shot 2022-08-16 at 12 35 50 PM

But input to +page load see's server type (note serverDate goes missing from the PageData type):
Screen Shot 2022-08-16 at 12 40 04 PM

@ollema
Copy link

ollema commented Aug 16, 2022

@CaptainCodeman running npx svelte-kit sync should update this but it would be nice if this was automatic (if possible)

@accuser
Copy link

accuser commented Aug 16, 2022

Had similar experience today, but turned out that the response wasn’t sterilisable. Once I’d sorted that out, all was peachy. Not saying that is what is going on here, but thought it worth mentioning.

@CaptainCodeman
Copy link
Contributor Author

running npx svelte-kit sync should update this but it would be nice if this was automatic (if possible)

That's unrealistic, it should happen while you work.

@CaptainCodeman
Copy link
Contributor Author

turned out that the response wasn’t sterilisable. Once I’d sorted that out, all was peachy. Not saying that is what is going on here, but thought it worth mentioning.

It's not that, it does it with the simplest props which are all definitely serializable (I added the dates while testing something else)

@AdrianGonz97
Copy link
Member

If it's any help, I've been reloading the vscode window via the command palette any time I've made changes to the returning data of the load function for +page.ts and +layout.ts. After a window reload, the types are updated to their expected types.

It's obviously not a solution to the problem, but it could be helpful in narrowing down where the problem is.

@Rich-Harris Rich-Harris added the bug Something isn't working label Aug 16, 2022
@Rich-Harris Rich-Harris added this to the 1.0 milestone Aug 16, 2022
@stausmar
Copy link

stausmar commented Aug 17, 2022

I have similar issues. Sometimes, the PageData type is even shown as unknown, although the correct types are imported.

+page.svelte

grafik

Running npx svelte-kit sync does not change anything. Also, reloading typescript, svelte language server, vscode window, etc... does not have any effect.

@sandstromdev
Copy link
Contributor

I've noticed the same thing with all exports of ./$types. If you open the ./$types file, all exports are typed correctly, but when importing them from a +page.svelte, they are typed as any, unknown or never.

As @AdrianGonz97 mentioned, reloading vscode helps, so my guess is that the problem is in vscode not reading the files on each update.

+page.server.ts
Screenshot 2022-08-17 at 12 42 51

+page.svelte
Screenshot 2022-08-17 at 12 43 18

@dummdidumm
Copy link
Member

This may be a problem in language-tools.

@dummdidumm
Copy link
Member

@CaptainCodeman could you check if your errors still persist? I'm having trouble to figure out if this is one or multiple issues. The "type doesn't update" issue should be resolved in the latest Svelte for VS Code extension version.

@CaptainCodeman
Copy link
Contributor Author

It seems better this morning, with all latest updates.

Still feels a little odd that things only update if you have the dev-server running, but the changes now appear to reflect when it is.

justuswilhelm added a commit to jwpconsulting/projectify-frontend that referenced this issue Sep 4, 2023
I stumbled upon this issue here when searching for what to do when PageData
types are not created:

sveltejs/kit#5940

The solution is to run svelte-kit sync. I have added a small helper to our
package.json and I call it from the CircleCI check:eslint step.

Also including this in our bisect helper
justuswilhelm added a commit to jwpconsulting/projectify-frontend that referenced this issue Sep 4, 2023
I stumbled upon this issue here when searching for what to do when PageData
types are not created:

sveltejs/kit#5940

The solution is to run svelte-kit sync. I have added a small helper to our
package.json and I call it from the CircleCI check:eslint step.

Also including this in our bisect helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants