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.

Client-side Routing without hitting the server

See original GitHub issue

Currently, when using Client-Side Routing (see docs here and there), the client-side pageContext is fetched from the server.

Some people want to be able to navigate between pages without hitting the Node.js SSR server. I’m opening a ticket for dicussing this.

I’m willing to implement this but this will require a couple of days work, so don’t expect this too soon.

👍 this ticket if you want this. The more 👍 this ticket collects the more will I increase the importance of this. And better yet, add a comment elaborating why this is crucial for you and I’ll then also increase urgency.

Edit: Most of the time, this is only about (negligible) server cost servings. For most apps, performance and cost implications are negligible. (Note that the static middleware of your Node.js server always needs to be hit anyways in order to get the latest code of the new page. It’s mostly only about reducing Node.js work load.)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:30
  • Comments:45 (39 by maintainers)

github_iconTop GitHub Comments

15reactions
brilloutcommented, Sep 15, 2021

addPageContext() has been renamed onBeforeRender() in v0.3.

Alright, so the plan is following:

  • You’ll be able to define onBeforeRender() hooks in .page.js files (instead of .page.server.js). Hooks defined in .page.js files are isomorphic: they can be called in Node.js as well as in the browser. When doing Client Routing, they are called in the browser.
  • If a page has no onBeforeRender() defined in its _default.page.server.js nor in the page’s .page.server.js then there is no request made to the server.

This means that if you move all your onBeforeRender() hooks from .page.server.js to .page.js then client-side routing will never make a request to your Node.js server.

I’m not sure what should happen if there are two onBeforeRender() hooks defined: one in .page.js and another in .page.server.js. I’ll probably throw a [Wrong Usage] exception until someone found a useful use case for it.

Thoughts?

10reactions
brilloutcommented, Sep 13, 2021

I’m finishing up the 0.3.0 release. I’ll re-consider this ticket after the release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When to use "client-side routing" or "server-side routing"?
A client side code (usually the routing library) catches this event, detects that the URL is not an external link, and then prevents...
Read more >
Client-side Routing without the JavaScript - DEV Community ‍ ‍
The trick was that through event delegation of click events we could trigger a client router without hydrating the page. From there we...
Read more >
Understanding single page apps & client-side routing
Let's get some clarity on what single page apps are, how they work, and where they differ from server-side routing.
Read more >
Chapter 17 Client-Side Routing
Chapter 17 Client-Side Routing. This chapter discusses how to use React to effectively develop Single Page Applications (SPA)—web applications that are ...
Read more >
Server-side vs Client-side Routing | by Wilbert Schepenaar
A server-side route will only request the data that's needed. No more, no less. · Every request results in a full-page refresh. That...
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