CF Adapter breaks URL.searchParams
See original GitHub issueDescribe 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:
- Created 2 years ago
- Reactions:5
- Comments:13 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Another workaround a bit less intrusive:
In hooks, handle():
In hooks, getSession():
In the
load
functions: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