queryParam.remove doesn't work

I call the following function at the end of my filter function to change the queryParam

function updateQueryParam(filterObj){
 let queryParam = filterObj
 for (let key in queryParam) {
 if (!queryParam[key].length === 0 || Object.keys(queryParam[key]).length === 0){
 delete queryParam[key]
    }
 else if (key === 'collection'){
      queryParam[key] = JSON.stringify(queryParam[key])
    }
  }
 wixLocation.queryParams.remove(Object.keys(wixLocation.query))
 console.log('original wixLocation.query')
 console.log(wixLocation.query)
 console.log('queryParam')
 console.log(queryParam)
 wixLocation.queryParams.add(queryParam)
 console.log('new wixLocation.query')
 console.log(wixLocation.query)

}

I select “ring” from my filter and the query string is correctly changes to “?category=ring” and I get the following log (edited for readability)

original wixLocation.query : {}
queryParam :                 {"category":["ring"]}
new wixLocation.query:       {"category":["ring"]}

However when I unselect the “ring” the URL query string remains as “?category=ring” despite getting the following log:

original wixLocation.query : {"category":["ring"]}
queryParam :                 {}
new wixLocation.query:       {}

And when I go to select “ring” again, I get the following log:

original wixLocation.query : {"category":["ring"]}
queryParam :                 {"category":["ring"]}
new wixLocation.query:       {"category":["ring"]}

From the logs as well as observing the URL, remove does what it should in the code as the new wixLocation.query === queryParam, but it doesn’t actually change the URL nor do the changes get saved. This issue gets compounded when I select multiple categories and it becomes something like “?category=ring&category=earring&category=bracelet” with nothing getting removed.

Am I implementing this wrong or is this yet another bug? I have read that remove is bugged when trying to run it multiple times within a function. But that was almost a year ago.

I don’t see a problem. Here’s my test:

$w.onReady(function () {

    // our starting URL
    console.log('orig', wixLocation.url);

    // add a drink
    wixLocation.queryParams.add({
       "drink": "beer",
       "brand": "Guinness"
    });
    console.log('add', wixLocation.url);

    // not fussy, so any old beer will do
    wixLocation.queryParams.remove(["brand"]);
    console.log('remove', wixLocation.url);
});

The console output:


Exactly as expected.

I didn’t try to debug your code, but I suspect that you’ll find the problem there.

@yisrael-wix I copied your code exactly to a test page (yes I remembered to import wixLocations to the new page) and the URL doesn’t change at all it just stays “https://briapril30.wixsite.com/miko-m/test” the log also stays the same

Even with my code, at least it adds the queryParam which makes it even more puzzling considering that the test page I made is completely empty, is identical to your code, but doesn’t work on mine while it does work on yours.

And to be clear, I am not doubting your code, you are way smarter than me, but it just isn’t working on my end for whatever reason.

I am using Chrome and Windows 10, though I dont think that makes any difference.

@yisrael-wix After further testing, my code is definitely not the issue and there seems to be an inherent issue with that particular wixsite. I duplicated my site and the queryParam seems to work fine on the duplicated site.

Maybe it has something do with the rendering? I reported issues with the new improvements and I think they reverted me to the old rendering or something. The new duplicated site seems to load much faster (just like how it was when the improvements were first rolled out) which makes me believe it is using the new rendering. Rendering doesn’t seem to be related but it is the only thing that is different between the two sites (that I know of).

@briapril30 Perhaps there is something wonky with the URL on the original site - maybe something got corrupted. Are you now using the duplicated new site, or are you still on the original? I’d like to send this issue to QA for evaluation, but they’ll need the problematic site.

@yisrael-wix I have renamed the the problematic site: https://briapril30.wixsite.com/problematic-site/shop

I’ll keep building my site on the duplicate as it seems to work and I want to get it finished ASAP.

I wouldn’t mind keeping the problematic site up until the QA finds out what went wrong so they can prevent it from happening again. Just let me know when it is okay to delete it and what went wrong (interested in learning).

No idea if this helps, but I’ve also noticed that when I choose multiple things from the same filter field (ie: ring, earring, bracelet)
I get two different URL query strings on the problematic site versus the duplicated site despite using the same code:

problematic site: /shop?category=ring&category=earring&category=bracelet
duplicated site: /shop?category=ring%2Cearring%2Cbracelet

Thanks!