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.

Incorrect query arguments handling in fetchPreRenderData

See original GitHub issue

Do you want to request a feature or report a bug?

A bug.

What is the current behaviour?

When visiting an URL that has GET query arguments passed (location.search) the resulting preact_prerender_data.json URL will be constructed using the full URL. E.g.

https://example.com/my-route/?some-query-argument=1 will result in the following:

https://example.com/my-route/?some-query-argument=1/preact_prerender_data.json

I’m not sure whether that’s a bug or by design, but in either case, it doesn’t seem like correct behavior.

What is the expected behaviour?

What probably should happen is normalizeUrl() should strip out the query arguments and they should be appended at the end.

So the resulting URL should be https://example.com/my-route/preact_prerender_data.json?some-query-argument=1

This would allow for more reliable behavior and better flexibility.

  1. For example, Facebook likes to append ?fbclid argument at the end of a shared url - current Implementation will be broken.
  2. Passing the arguments at the end of query args would allow to handle those server-side (E.g… if preact_prerender_data.json is not a statically generated file but instead just an endpoint.

I’m happy to submit a PR just as long as y’all are interested.

[EDIT]

app.js

import { h } from 'preact';
import { Router } from 'preact-router';
import { Provider } from '@preact/prerender-data-provider';
import Header from './header';

// Code-splitting is automated for `routes` directory
import Home from '../routes/home';
import Profile from '../routes/profile';

const App = (props) => (
	<Provider value={props}>
	<div id="app">
		<Header />
		<Router>
			<Home path="/" />
			<Profile path="/profile/" user="me" />
			<Profile path="/profile/:user" />
		</Router>
	</div>
	</Provider>
)

export default App;

home.js

import { h } from 'preact';
import style from './style.css';
import { usePrerenderData } from '@preact/prerender-data-provider';

const Home = (props) => {
	console.log(props.url);
	const [data, loading, error] = usePrerenderData(props)
	return (
		<div class={style.home}>
		<h1>Home</h1>
		<p>This is the Home component.</p>
	</div>
)};

export default Home;
Screen Shot 2020-11-01 at 1 45 33 PM

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mjmaurercommented, Jun 30, 2021

@rinatkhaziev did you end up making a PR? I might take this on if not.

0reactions
rinatkhazievcommented, Jul 2, 2021

@mjmaurer to my greatest shame, I have not!

An example of what I have in mind is this, but there are tons of other ways one can do it.

let url = document.location.href.split('?');
let [ base, ...query ] = url;
let formattedUrl =  base + '/preact_prerender_data.json?' + query.join('&');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Key arguments in Apollo Client - Apollo GraphQL Docs
If no arguments are key arguments (you configure this by setting keyArgs: false ), the field's storage key is just the field's name,...
Read more >
java - How to handle requests without or with incorrect query ...
So my task is to handle request without or with incorrect query parameters. The correct one that return data GET {url}/v1/transactions/?from= ...
Read more >
Error "Invalid value for query parameter" and failed to send a ...
Learn how to send a proper request with array query parameters with APIKit when invalid query parameter error occurs.
Read more >
An SEO Guide to URL Parameter Handling
The problem is we can't simply wish parameters away. ... Also known by the aliases of query strings or URL variables, parameters are...
Read more >
Create a parameter query in Microsoft Query
When you query data in Excel, you might want to use an input value - a parameter - to specify something about the...
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