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.

Not updating js module after route change

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am trying to load lottie animations after every click of the button. I chose to not load animation itself but rather use routing. So every click will create a route localhost/1 -> it should load 1.json (lottie animation), localhost/2 -> it should load …json etc.

The problem is that I tried to use every lifecycle and also statehaschanged but nothing helped to change the lottie animation even if parameter is passing correctly. So first change works Index->/number but after same animation is being display despite the fact the number is changing.

Could you please help me out?

Thank you.

@page "/{animNumber:int}"
@inject IJSRuntime JSRuntime
@inject NavigationManager navigationManager

<PageTitle>Index</PageTitle>

<h3>Anim @animNumber</h3>
<lottie-player src="lottie/(@animNumber).json" background="transparent" speed="1" style="width: 300px; height: 300px;" loop autoplay></lottie-player>
<audio id="roar" src="/sound/duo.mp3" @onended="NavigateToNextAnimation" />
<button id="soundButton" @onclick="PlaySound">Click me!</button>

@code {
    [Parameter]
    public int animNumber { get; set; }

    public async Task PlaySound()
    {
        await JSRuntime.InvokeAsync<string>("PlayAudio", "roar");
        animNumber++;
    }
    public void NavigateToNextAnimation()
    {
        navigationManager.NavigateTo($"/{animNumber}");
    }
}

Expected Behavior

To change animation after every button click.

Steps To Reproduce

Minimal version: https://github.com/Laftek/BlazorNotReloadingLottie.git

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Laftekcommented, Nov 22, 2022

@MackinnonBuck Thank you! it works now! Thanks again!

0reactions
MackinnonBuckcommented, Nov 21, 2022

@Laftek If the generated HTML is correct, then this seems to be a bug in the lottie-player custom element, not Blazor. It’s possible that the custom element isn’t reacting to changes to its attribute values. You could try adding a @key attribute to the custom element and setting its value to animNumber to force the custom element to be destroyed and re-created when animNumber changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Routers Switch is not updating when the route has ...
To solve the issue, you can force re-mount on route change by passing a key prop to the Category component which changes on...
Read more >
Switch not updating Route when route change occurs #130
If Switch is never re-rendered, it doesn't update which causes it to not update which Route component it should render.
Read more >
How to Update the Application Title based on Routing ...
The Routing Configuration. Open the app-routing.module.ts file, and create the initial routes.
Read more >
Router tutorial: tour of heroes
In this tutorial, you build upon a basic router configuration to explore features such as child routes, route parameters, lazy load NgModules, guard...
Read more >
Building Isomorphic JavaScript Apps: From Concept to ...
You should be able to click through the links, see the address bar update in ... HTTP router, call, and since Browserify was...
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