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.

Fully dynamic loadable is not reactive

See original GitHub issue

🐛 Bug Report

Seems like only the very first prop sent to the loadable component in a dynamic context is respected, further updates to the props have no effect. Same applies to loadable.lib

To Reproduce

https://codesandbox.io/s/3wn6vo7ym

Expected behavior

Changing props will work reactively. An “easy” fix is to set a key prop to the loadable component, this works in the case of using a loadable component (although it seems like a hack) but for loadable.lib, this will trigger an unmount and remount of all children of the component, which is sometimes not desired as the rendered tree could be similar, you want to perform animations, etc.

## System:
 - OS: macOS 10.14.3
 - CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
 - Memory: 99.34 MB / 16.00 GB
 - Shell: 5.3 - /bin/zsh
## Binaries:
 - Node: 10.15.2 - /usr/local/opt/node@10/bin/node
 - Yarn: 1.15.2 - /usr/local/bin/yarn
 - npm: 6.4.1 - /usr/local/opt/node@10/bin/npm
 - Watchman: 4.9.0 - /usr/local/bin/watchman
## npmPackages:
 - @loadable/babel-plugin: ^5.7.2 => 5.7.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gregbergecommented, Mar 25, 2019

I think we could make it work the way you expect it to work. But it is a big change. I need time to work on it. For now if you don’t need SSR a workaround is to create your own loadable.lib component.

1reaction
luishdz1010commented, Mar 25, 2019

@theKashey The first approach is already possible, but it does not have the same behavior as if it were implemented inside loadable. Changing the key treats the component as a totally different one, so an unmount/remount is guaranteed in all prop changes.

If we don’t use key and let the loadable invalidate its own state after props change, it will most of the time also generate a unmount/mount cycle except in the case where new was previously loaded in a previous render cycle. In that specific case, the loadable will behave differently than usingkey because it will not unmount/remount its children, since it will simply pass new to the function-as-a-child, it is then the responsibility of the function-as-a-child to render whatever new/old component it wants.

This is what I’d expect, if I change the query in an Apollo’s <Query> component I get a completely new data and loading cycle, and I’d argue conceptually the loadable.lib should work similar to <Query> in that regard.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading dynamic Reactive Forms , doesn't wait for the http call ...
I am trying to load a dynamic fields forms based on the input from an http services (which is supposed to provide meta...
Read more >
Documentation - SolidJS · Reactive Javascript Library
A declarative, efficient and flexible JavaScript library for building user interfaces.
Read more >
Load external JS in Outsystems Reactive Web App
Hi there! I'm trying to load an external js file into an OutSystems Reactive Web App Module inside of a personal development environment....
Read more >
Dynamic component loader - Angular
Component templates are not always fixed. An application might need to load new components at ... Now Angular knows where to dynamically load...
Read more >
Chapter 10 Dynamic UI | Mastering Shiny
That's because it's reactive: the app must load, trigger a reactive event, which calls the server function, yielding HTML to insert into 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