-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always serializes to Immutable.Map if multiple immutable libs are used #32
Comments
I think this should work, that's an interesting pitfall with lerna and link to be aware of when things use Would take a PR for this. |
I'll see what I can do about it. But that is a short-term approach and we need better solution for sure. btw this is fairly common issue as far as I can tell. |
Same issues here, waiting PR for a fix. |
Unfortunately this problem is not specific to transit-immutable-js only. Several other "singlton" libraries out there stop working properly with symlinks (done by Extracting own common lib can get you only this far. Until you use some 3rd-party that depend on one of your "proxied" library. Our final solution for this problem looks this way. // Server-side
const jsHook = require('babel-register');
jsHook({
// ...
plugins: [
[require.resolve('babel-plugin-module-resolver'), {
root: [path.join(process.cwd(), 'node_modules'), './node_modules']
}]
]
});
// Client-side, webpack.config.js
module.exports = {
// ...
resolve: {
modules: [
path.join(process.cwd(), 'node_modules'),
'node_modules'
]
}
}; NodeJS default behaviour is to search for modules depth-first (so it will follow all symlinks until reaches the deepest and closes library that is required. Changes above flip this upside-down and node would look for a dependency first at entry point and only then will fall back to default behaviour. It works well for all our projects now. Note that We've spent quite a bit of time making these things work and ended up with this solution. Pretty sure I've got couple of grey hairs now added... |
Apparently |
Yep, in general I try and avoid instanceof checks, but transit doesn't give me much choice in this case. |
any news about this issue? |
I actually wrote my owt transit library about 200 lines long that replaces both this one and whole transit-js. It is not hard especially if you are not trying to solve a one-fits-all usecase (not opensourse since we don't want to support generic cases and just keep it focused on our own data sttuctures) I need to find some time soon to backport part of its code here to solve this issue. It is actually pretty straightforward |
I had this same problem, I ended up figuring out it was because react native had it's own instance of immutable installed in |
We've spent quite some time debugging one very strange issue. The effect was in
Immutable.List
being serialized and later de-serialized intoImmutable.Map
.I will try to explain the problem as short as possible and suggest a solution at the end.
Summary
instanceof
comparisons oftransit-js
fails to compare Immutable types if we have multipleimmutable
libraries used.Explanation
We are using Lerna monorepo and all internal packages there are symlinked (the same effect can happen if you use
npm link
without doing work in monorepo at all)Bootstrapped working project structure:
As you can see symlinked
lib
will also have its ownimmutable
like:As soon as we export anything Immutable in
lib
and use it inapp
, trying to serialize the state would result in fallback to thedefault
case oftransit-immutable-js
:The reason for that is
transit-js
tries to do a match by usinginstanceof
andlib->Immutable.List
does not matchapp->Immutable.List
Possible solution
Instead of passing a mapping of
Immutable.X
totransit-js
always usedefault
case and use native ImmutableJS methods likeImmutable.List.isList(obj)
to do matching.We checked that in the app's code and
Immutable.List.isList(obj)
works perfectly no matter whatimmutable
is used there.We did not check this on
transit-immutable-js
code yet. Need to see if it even possible (would be iftransit-js
somehow givesobj
back totag
function of writeHandlerThe text was updated successfully, but these errors were encountered: