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.

Crosstalk between different unstated state containers for production builds

See original GitHub issue

šŸ› bug report

Imagine I’m making a questionnaire app. I’m using unstated (the non-next version) to, well, maintain state. One of the things I’m using it for is for paging, of which I have a few different nested routes. There’s the main router, then one for questions, and then another pageable component elsewhere. Hopefully I can show via this mildly baffling line:

[MainRouteContainer:1,2,3,4,5:[QuestionsRouteContainer:1,2,...13],6,7,8,...]

Initially I had a general route container that the others extended. It looks a bit like this:

import { Container } from 'unstated';

class RouteContainer extends Container {
  state = { current: 0, direction: null };
  increment = () => {
    this.setState(({ current }) => ({ current: current + 1, direction: 'increment' }));
  }
  decrement = () => {
    this.setState(({ current }) => ({ current: current - 1, direction: 'decrement' }));
  }
  setPage = (page) => {
    this.setState({ current: page });
  }
}

export default RouteContainer;

Then I had MainRouteContainer and QuestionsRouteContainer which extended the above component. This worked fine when running from parcel index.html but doing parcel build index.html would make it so you would route normally in the MainRouteContainer, then you’d get to the questions page with the subrouting, and the questions would start at index 5, basically sharing the same index as the main route, even though they are different classes technically.

This was fixed by making the QuestionsRouteContainer no longer extend the RouteContainer and I just copied the contents of the RouteContainer into it, and it was fine. However I later added a third router which also had duplicated rather than extended content, but this weird bug came back again on production builds, where the third router would start at a non-0 index, taking its value from MainRouteContainer.

At this point I just scrapped RouteContainer and made all three containers use their entire own state and functions, but now the initial bug with the questions came back, even with no class extension!

The only way I managed to fix this is to make the three containers all use entirely different variable names for current. So there’s currentM, currentQ, currentP. Then the bugs are squashed.

So I’m thinking, is ParcelJS thinking that this current variable is the same and shared between the three containers? And has this been experienced before or is it specific to my combination of unstated and parcel?

I will hopefully fill out this issue a bit more when I’m less busy, but if anyone knows what’s going on I’d be really grateful.

Thanks!

šŸŒ Your Environment

Software Version(s)
Parcel 1.12.3
Node v10.15.3 but also experienced on v12
npm/Yarn npm 6.9.0
Operating System MacOS but also Ubuntu

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mischniccommented, Sep 26, 2019

What counts as ā€œidenticalā€?

In this case: the JS code after processing (e.g. babel/terser) is the same string. This is because the asset has is computed based solely on this string. So your identical JS modules all have the same hash and then overwrite themselves.

I’m closing this as a duplicate, feel free to ask any further questions though.

1reaction
mischniccommented, Sep 26, 2019

The only way I managed to fix this is to make the three containers all use entirely different variable names for current. So there’s currentM, currentQ, currentP. Then the bugs are squashed.

I didn’t completely understand your description of your project and the issue, bug one known bug is that, in production builds, having multiple files with the same contents actually ā€œmergedā€ them so that in the places where one of these modules was imported, the same exact value was returned (#3523). So: if you the JS files for your different paging state containers all have the exact same content, then this is a duplicate of #3523 (and you already found a workaround I would have suggested).

Read more comments on GitHub >

github_iconTop Results From Across the Web

React UnStated — Aggregation of state between different ...
I recently started using react unstated. I took help of this quick start guide. It took me a couple of readings to understand...
Read more >
Use Unstated to share state between two separate rendered ...
In this lesson I refactor a React component that uses local state to use Unstated. I also show how you can utilize Unstated...
Read more >
Transcript of RNR 183 - Debugging Techniques | React Native Radio
Yeah, I'm going to be switching it up and using different synonyms. ... And you can build your own plugins for other state...
Read more >
Securely Using Software Assurance (SwA) Tools in the ... - DTIC
Using many different kinds of SwA tools is an excellent approach for detecting vulnerabilities in software during development.
Read more >
Untitled
Parkash kaur songs free download, Watchmojo worst cgi, Twilight sparkle magic glow, 3 fluoro 1 pentyne, Different types of cigarette lighters, Personal chefĀ ......
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