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.

Initialstate is not updated for subsequent routes

See original GitHub issue

Try the example below and for all paths you will get the same initialstate. Seems it only uses the first one. I would expect for every page initialstate.data to be the path of that page.

// src/main.ts

// ...

export const createApp = ViteSSG(
  App,
  { routes },
  ({ app, router, routes, isClient, initialState, routePath }) => {
    // ...

    if (import.meta.env.SSR) {
      initialState.data = routePath 
    } else {
    
      console.log(initialState.data) // => { routePath :"/" }
    }

    // ...
  }
)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:38 (18 by maintainers)

github_iconTop GitHub Comments

8reactions
userquincommented, Sep 10, 2021

@husayt just clone this repo and change the lines 91 and 120: on former remove the inicial state and later add the initial state, on build you will have on each html page its own state, just modify the router example with your logic

2reactions
husaytcommented, Aug 27, 2021

@userquin if this issue is fixed I expect the code above to just work. That would make vite-SSG so much more powerful and flexible

Read more comments on GitHub >

github_iconTop Results From Across the Web

NextJS initial state is not updating when routing to same page ...
On subsequent page renders (client side routing), NextJS executes it on the client, but this means that data is not available before page ......
Read more >
NextJS initial state is not updating when routing to same page ...
On subsequent page renders (client side routing), NextJS executes it on the client, but this means that data is not available before page...
Read more >
com.fulcrologic.fulcro.routing.legacy-ui-routers - cljdoc
If any of the routers are dynamic, then this mutation will check to see if the target routes are loaded. If any are...
Read more >
Initial State Simulations - Innovyze
When a simulation is carried out, the state of an InfoWorks network at a specified date and time may be saved for use...
Read more >
Handling user authentication with Redux Toolkit
This logic can be extracted into a single ProtectedRoute component, and we are going to create that next. Protected routes with React Router....
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