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

Spurious prop warnings with +page.svelte files #5980

Closed
stephenlrandall opened this issue Aug 17, 2022 · 16 comments · Fixed by #6071, #6078 or #6798
Closed

Spurious prop warnings with +page.svelte files #5980

stephenlrandall opened this issue Aug 17, 2022 · 16 comments · Fixed by #6071, #6078 or #6798
Milestone

Comments

@stephenlrandall
Copy link
Contributor

Describe the bug

On each route not using a load function, the console has

[Warning] <Page> was created with unknown prop 'data' (+page.svelte, line ...)
[Warning] <Page> was created with unknown prop 'errors' (+page.svelte, line ...)

These can be removed with the boilerplate

export let data;
export let errors;

in the +page.svelte files for those routes, but ideally the warnings would not be present unless the route has an associated load function.

Reproduction

Launch a SvelteKit app that includes routes which do not explicitly accept data or errors and check the console.

Logs

No response

System Info

System:
    OS: macOS 12.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 25.14 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.4.0 - ~/Library/pnpm/node
    npm: 8.12.1 - ~/Library/pnpm/npm
  Browsers:
    Safari: 15.6
  npmPackages:
    @sveltejs/adapter-static: 1.0.0-next.38 => 1.0.0-next.38 
    @sveltejs/kit: next => 1.0.0-next.411 
    svelte: ^3.49.0 => 3.49.0 
    vite: ^3.0.8 => 3.0.8

Severity

annoyance

Additional Information

No response

@dummdidumm
Copy link
Member

dummdidumm commented Aug 17, 2022

This comes from a warning in Svelte core, which we IMHO could just remove. I also believe there is some (closed?) issue in this repo already noticing the same thing in a different context.

@sserdyuk
Copy link

The warning is helpful if you accidentally use the wrong binding on a component.

@benmccann
Copy link
Member

sveltejs/svelte#4652 looks to be the issue in the Svelte repo. If we're going to be removing annoying warnings then I'd also nominate sveltejs/svelte#6325

@benmccann benmccann added this to the 1.0 milestone Aug 17, 2022
@stephenlrandall
Copy link
Contributor Author

stephenlrandall commented Aug 17, 2022

I agree that the warning is useful in many cases (I've definitely caught a lot of issues thanks to those warnings), but only when I'm intentionally passing props around. If I don't have a +page.js in a route, I wouldn't expect data or errors to be passed in to the +page.svelte file and I wouldn't want to be warned that I'm missing some boilerplate export let data line for an unused data.

@Rich-Harris
Copy link
Member

Agree, the warning should only appear if we're passing data or errors and they're not being received

@charbelnicolas

This comment was marked as duplicate.

@dummdidumm
Copy link
Member

The problem is - how do we leave the warning in place while silencing it for this use case? There would have to be some kind of runtime code involved. Two possibilities I can think of:

  • Svelte exposes some kind of method that says "surpress the warnings of type X" and another one that says "stop surpressing warnings of type X", which we call before and after setting the props
  • Svelte exposes some kind of info on its components in dev mode: "these are the props I expect", and SvelteKit's component uses that info to not pass data/errors in this case

@Zamiell

This comment was marked as duplicate.

@aradalvand
Copy link
Contributor

aradalvand commented Aug 18, 2022

Agree, the warning should only appear if we're passing data or errors and they're not being received

@Rich-Harris Perhaps not even in those cases, sometimes you're just returning data for the layout(s) to consume, you don't necessarily need it in the +page.svelte itself. And a warning in these cases would also be annoying.

dummdidumm added a commit that referenced this issue Aug 19, 2022
This is a hack, but it's a working quick solution. Fixes #5980
Rich-Harris pushed a commit that referenced this issue Aug 19, 2022
This is a hack, but it's a working quick solution. Fixes #5980
@kevinrenskers
Copy link

This got closed a while back but I am still seeing frequent <Page> was created with unknown prop 'errors' warnings for pages without a load function.

@charbelnicolas
Copy link

Yeah, I still get them sometimes when hot reloading too

@dummdidumm
Copy link
Member

Reopening as they can appear as a result of Vite hot module reload. Not sure how we can silence these except turning on the warning-silence-hack all the time.

@dummdidumm dummdidumm reopened this Sep 4, 2022
@kevinrenskers
Copy link

Yeah, I still get them sometimes when hot reloading too

True, it seems limited to HMR.

dummdidumm added a commit that referenced this issue Sep 14, 2022
Fixes #5980
This could result in false negatives but the probability for that is minimal and not seing the warning sometimes is better than seing the warning without being able to do anything about it
Rich-Harris pushed a commit that referenced this issue Sep 14, 2022
Fixes #5980
This could result in false negatives but the probability for that is minimal and not seing the warning sometimes is better than seing the warning without being able to do anything about it
@TeamDman
Copy link

TeamDman commented Dec 9, 2022

Also getting this with the Error page it seems

<Error> was created with unknown prop 'data'
<Error> was created with unknown prop 'form'

image

@sonylomo
Copy link

@TeamDman I'm getting the same error message. Did you find a possible solution?

@TeamDman
Copy link

Just ignored it for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet