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

Possible bug: Inconsistent behavior with Node 20 #26

Open
devinellis opened this issue Apr 26, 2023 · 12 comments
Open

Possible bug: Inconsistent behavior with Node 20 #26

devinellis opened this issue Apr 26, 2023 · 12 comments

Comments

@devinellis
Copy link

Describe the bug

First off, I'll say that I haven't verified if this happens without the use of your plugin.

const search = queryParam('q', ssp.string(), {pushHistory: false})
...
<input type="search" name="search" placeholder="Search" bind:value={$search} />

Running this on Node 18, no calls to __data.json happen when typing in the input. But when I upgrade to Node 20, I see a request to __data.json on every keystroke.

It took me a looong time to figure out what the culprit was. I created a whole Stackblitz for you, only to find that the issue wasn't there because apparently it runs Node 16.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-d1rzdh?file=README.md

Logs

No response

@stackblitz
Copy link

stackblitz bot commented Apr 26, 2023

@paoloricciuti
Copy link
Owner

Mmm in the stackblitz you sent is completely normal that no request is made...are you saying that if you upgrade to node 20 the load function will run on every keystroke? That seems like a sveltekit bug more than a sveltekit-search-params bug but i'll take a look...in the meantime please can you confirm this?

@devinellis
Copy link
Author

Yes that's correct, sorry for the confusion. I couldn't find a way to get stackblitz to use node 20.

For example, the project im working on had been on Node 18 and it was fine. But at some point my docker image updated to Node 20 and that's when the issue began. Forcing docker to node 18 fixes the problem.

@paoloricciuti
Copy link
Owner

I can confirm this is actually a bug with sveltekit...do you prefer to open this issue on the kit repository? Otherwise i can do it for you.

@devinellis
Copy link
Author

If you don’t mind maybe you can, if you have clean repro steps. It seems more important coming from a plugin maintainer such as yourself.

@paoloricciuti
Copy link
Owner

Sure i'll prepare a repro and open an issue on kit...thanks for reporting

@paoloricciuti
Copy link
Owner

Uh i can't reproduce anymore even with node 20 and your code

@paoloricciuti
Copy link
Owner

@devinellis
Copy link
Author

If I run $ node -v in the terminal on that gitpod, it says Node v18. I can't figure out where that's being configured from... I've never used gitpod before.

@paoloricciuti
Copy link
Owner

If I run $ node -v in the terminal on that gitpod, it says Node v18. I can't figure out where that's being configured from... I've never used gitpod before.

You can just nvm install 20 in the terminal and than run the app

@devinellis
Copy link
Author

OK I figured out how to repro. You need to check the URL in page.server.ts and it somehow becomes aware of that. Change the handler to something like this:

export const load = ({url}) => {
  const now = new Date().toString();
  if(url.searchParams.has('a')) {
    console.log('noop');
  }
  console.log(now);
  return { now };
};

I can't get it to not happen, even switching back to node 18 in gitpod, downgrading sveltekit, etc. Its weird that this doesn't happen when I use the docker image 18-alpine, because the server handler is the exact same.

@paoloricciuti
Copy link
Owner

OK I figured out how to repro. You need to check the URL in page.server.ts and it somehow becomes aware of that. Change the handler to something like this:

export const load = ({url}) => {
  const now = new Date().toString();
  if(url.searchParams.has('a')) {
    console.log('noop');
  }
  console.log(now);
  return { now };
};

I can't get it to not happen, even switching back to node 18 in gitpod, downgrading sveltekit, etc. Its weird that this doesn't happen when I use the docker image 18-alpine, because the server handler is the exact same.

If you do this than it's the actual expected behavior of sveltekit...if you use searchParams inside the load function it will invalidate and rerun when the search params change

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

2 participants