Bit: ConsumerComponent mutations after writing to the capsule

Created on 3 Apr 2020  路  5Comments  路  Source: teambit/bit

Two concrete mutations I found, but I'm sure there are more.

  1. component.dists.writeDistsFiles. capsule - false, non-capsule - sometimes true.
  2. writeToPath. capsule ".", non-capsule component dir.

The Problem
The ConsumerComponent instances are cached. Before writing to the capsules, some props are changed. Then, when loading the components outside the capsules, Bit loads them from the cache with the mutated props.
For example, when writing the component to the capsule, component.dists.writeDistsFiles is false, however, when the command is build, at a later step, where it should write the dists, it unexpectedly skips the write because of this prop.

A Quick workaround
For now, in the bit-compile branch, I clone the components before writing them to the capsule, so the won't affect anything else.

An alternative, which I used for the old capsules is to maintain two caches, one for the capsules and one for the workspace.
Here, however, I'm unsure how easy would it be. I see that components are sometimes loaded from the Graph class, which is used for the workspace as well.

@ranm8 , @GiladShoham , @imsnif , @qballer your suggestions are welcome.

typbug

All 5 comments

Do you have cases where you want side affects to be cached?

That's a major issue.
We should discuss the component life cycle and mutation over a meeting.
it's similar for the component config and much other stuff.
Actually an extension might mutate a component in an unexpected way and create many hard to reproduce bugs.

@davidfirst is this issue now settled?

@ranm8 , as mentioned above, I have made a workaround so it's not a blocker.
But we do need to address this issue. See also Gilad's comment.

As discussed, a preferable way is to understand where the capsule mutates the ConsumerComponent and avoid such mutations.
However, I'm not sure that this is the best solution. What if the capsule will do other changes in the future? since the same cache serves both the capsule and the workspace, the risk is still there.

I'd be happy to get your input on this.

I think that we should address it somewhere very deep in the architecture.
Something like always clone the component before passing it to extension to completely prevent mutations.
Or make everything in consumer component private to allow only changes made by setters/functions we explicitly expose.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

williamluke4 picture williamluke4  路  4Comments

JamesNorris11 picture JamesNorris11  路  4Comments

amadeogallardo picture amadeogallardo  路  4Comments

KutnerUri picture KutnerUri  路  3Comments

JGJP picture JGJP  路  3Comments