question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CF Adapter breaks URL.searchParams

See original GitHub issue

Describe the bug

Method searchParams called on incompatible receiver [object Object] TypeError: Method searchParams called on incompatible receiver [object Object]

Reproduction

	import { fetchFates } from "$lib/request"
	export const prerender = false;
	/** @type {import('@sveltejs/kit@next').Load} */
	export async function load({ url }) {
		//console.log("url is:", url)
		let tag = url.searchParams.get("tag")
		let targetType = url.searchParams.get("target_type")
        console.log(tag)
		const searchUrl = `/api/v2/search/tags?target_type=${targetType}&tag=${tag}`;
		const res = await fetchFates(searchUrl);

		if (res.ok) {
            let data = await res.json()
			return {
				props: {
					data: data,
                    targetType: targetType,
                    tag: tag
				}
			};
		}

		return {
			status: res.status,
			error: new Error(`Tag Search Error`)
		};
	}
</script>
<script lang="ts">
    import CardContainer from "$lib/cards/CardContainer.svelte"
    import BotCard from "$lib/cards/BotCard.svelte"
    import SearchBar from "$lib/base/SearchBar.svelte"
    import Tag from "$lib/base/Tag.svelte";
import { session } from "$app/stores";
    export let data: any;
    export let targetType: string;
</script>
<section>
	<h1>Fates List</h1>
	<h2 class="best-bots">Find the best bots for your servers!</h2>
</section>
<SearchBar type={targetType} query=""></SearchBar>
<Tag targetType={targetType} tags={data.tags_fixed}></Tag>
<CardContainer>
	{#each data.search_res as bot}
		<BotCard data={bot} type={targetType} rand={false}/>
	{/each}
</CardContainer>

<style>
	h1 {
		font-size: 50px;
		margin: 0px;
	}

	h2 {
		font-size: 40px;
		margin: 0px;
	}

	.best-bots {
		opacity: 0.6;
	}
	section {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		flex: 1;
		overflow: hidden;
	}
</style>

This code will give:

Method searchParams called on incompatible receiver [object Object] TypeError: Method searchParams called on incompatible receiver [object Object]

Logs

No logs are reported

System Info

System:
    OS: Linux 5.15 Fedora Linux 35 (Cloud Edition)
    CPU: (2) x64 DO-Regular
    Memory: 688.41 MB / 3.82 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/bin/node
    npm: 8.1.0 - /usr/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.7 
    @sveltejs/adapter-cloudflare: ^1.0.0-next.4 => 1.0.0-next.5 
    @sveltejs/adapter-node: ^1.0.0-next.57 => 1.0.0-next.58 
    @sveltejs/kit: next => 1.0.0-next.212 
    svelte: ^3.44.0 => 3.44.3 

issue itself is with cf pages

Severity

blocking all usage of SvelteKit

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
stephanecommented, Jan 12, 2022

Another workaround a bit less intrusive:

In hooks, handle():

request.locals.fixedUrl = request.url.toJSON();

In hooks, getSession():

return {
    fixedUrl: locals.fixedUrl
};

In the load functions:

export async function load({ session }) {
    const url = new URL(session.fixedUrl);
}
1reaction
Rich-Harriscommented, Jan 22, 2022

Can you check if this is still happening with the latest versions of everything? ‘method called on incompatible receiver’ makes me think this is proxy-related — we used to use a proxy indiscriminately to prevent illegal query access during prerendering, but as of https://github.com/sveltejs/kit/pull/3314 we only create the proxy when prerendering is true

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL.searchParams - Web APIs - MDN Web Docs - Mozilla
The searchParams readonly property of the URL interface returns a URLSearchParams object allowing access to the GET decoded query arguments ...
Read more >
Issue with dynamic pages : r/sveltejs - Reddit
Hi Everyone, I have a sveltekit app where I've defined a page as dynamic with the following svelte.config.js import adapter from…
Read more >
With React Query - React Location - TanStack
'undefined') {\\n \u002F\u002F For browsers use XHR adapter\\n adapter ... jf(c, d);\\n\\n case \\\"selectionchange\\\":\\n if (cf) break;\\n\\n case ...
Read more >
Cisco Intersight Managed Mode Configuration Guide
To view a list of Cisco trademarks, go to this URL: ... Creating an Adapter Configuration Policy 97. Creating a LAN Connectivity Policy...
Read more >
How to convert URL parameters to a JavaScript object?
This includes using URLSearchParams and iterators let params = new URLSearchParams('abc=foo&def=%5Basf%5D&xyz=5'); params.get("abc"); // "foo".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found