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.

isChangingPage Is Set "Too Late"

See original GitHub issue

Description

While trying to use the $isChangingPage helper, I noticed that it fires “too late”. It won’t set to true until after the page is already navigated to, which makes it relatively useless. 😞

I believe the issue here is that the value isn’t set to true until after the route’s components have been preloaded

Would it not make sense to just move the stores.isChangingPage.set(true) bit to before the route.api.preload() call? Or, could it not be maybe moved to be set as a hook in the $beforeUrlChange helper, similar to how its currently set to off in $afterPageLoad?

Package Versions

$ npm ls --depth=0 @roxi/routify svelte
variedvibe.com@1.0.0 REDACTED
├── @roxi/routify@2.18.4
└── svelte@3.44.3

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jakobrosenbergcommented, Jan 2, 2022

Hi @Rican7, moving $isChangingPage would be a breaking change. The helper only shows when a page is actually changing, not when it is loading.

There are a few ways this could be handled:

PR idea 1

We could do something like this instead

    stores.isLoadingPage.set(true)

    //preload components in parallel
    route.api.preload().then(() => {
      stores.isChangingPage.set(true)
      stores.isLoadingPage.set(false)

      //run callback in Router.svelte    
      callback(nodes)
    })
if ($isLoadingPage || $isChangingPage) { ... }

PR idea 2

Another option would be to introduce a new Routify option

    if (options.changingPageIncludesPreload)
      stores.isChangingPage.set(true)

    //preload components in parallel
    route.api.preload().then(() => {
      stores.isChangingPage.set(true)
      //run callback in Router.svelte    
      callback(nodes)
    })

Alternatively

you could also use a combination of beforeUrlChange and afterPageLoad.

import { beforeUrlChange, afterPageLoad } from "@roxi/routify"

let loading = false

$beforeUrlChange(() => {
  loading = true
  return true
})
$afterPageLoad(() => (loading = false))
1reaction
Rican7commented, Jan 2, 2022

I could try and see if I’m able to, yea. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Late is Too Late to Redirect Pages of Domain for SEO
Is it too late to re-redirect the bots. Short answer? No. You are right about redirecting to relevant content. While it has been...
Read more >
setState doesn't update the state immediately - Stack Overflow
setState is asynchronous. It means you can't call it on one line and assume the state has changed on the next. According to...
Read more >
Start page numbering later in your document - Microsoft Support
Remove the page number from the first page. Go to Insert > Header or Footer > Edit Header or Edit Footer. Select Different...
Read more >
How to Change Your Facebook Page URL / Username Easily ...
Wondering how to change your Facebook Page URL? Here's the step-by-step tutorial, plus cautions and troubleshooting tips for changing your ...
Read more >
Move a Website and Change URL | Google Search Central
Learn how to change the URLs of existing site pages, including domain name ... the next step is to set up HTTP 301...
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