Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Version 2.0 #212

Merged
merged 34 commits into from
Apr 6, 2020
Merged

Version 2.0 #212

merged 34 commits into from
Apr 6, 2020

Conversation

danielkcz
Copy link
Collaborator

@danielkcz danielkcz commented Aug 23, 2019

I think it's time to get this thing out. It seems that React 16.9 has included some preliminary changes for upcoming Concurrent mode which are causing trouble with the current test.

With the code of useObserver from next branch, tests are passing again although there is a bunch of act warnings which might be false positive as it's actually necessary to simulate commit phases and similar. We can review that later.

Personally, we have been using this branch for a couple of months now in production and no related problem seems to occur.

Changelog follows:

## Breaking changes:
 * Remove deprecated hooks `useComputed`, `useDisposable`, `useObservable`
 * Internals of `useObserver` are rewritten to support React Strict mode [#121] @RoystonS 
 * UMD bundle is moved to `mobxreactlite.umd.production.min.js` or `mobxreactlite.umd.development.js` respectively.
 * React Native no longer has a specific build, the regular one can be used

This branch has diverted from master fair amount and is really hard to rebase. For any further updates just merge master directly and we will squash later.

RoystonS and others added 12 commits April 28, 2019 13:41
* Test cleaning up reactions for uncommitted components

* First attempt at a fix for cleaning up reactions from uncommitted components

* Use debounce instead of fixed interval

* Add unit test for missing observable changes before useEffect runs

This is a test to check that observable changes made between the
first component render and commit are not lost.

It currently fails (and did so before the change in PR #119)

* Add test for cleanup timer firing too early for some components

This demonstrates (in a slightly contrived way) how, if the
cleanup timer fires between a recent component being
rendered and it being committed, that it would incorrectly
tidy up a reaction for a soon-to-be-committed component.

* Update test for missing changes to check Strict and non-Strict mode

We had an existing test to check that observable changes between render
and commit didn't go missing, but it only checked in Strict mode, and
there's a problem with non-Strict mode.

* Add cleanup tracking and more tests

This adds full cleanup tracking, and even more tests:

- we now track how long ago potentially leaked reactions
were created, and only clean those that were leaked 'a while ago'
- if a reaction is incorrectly disposed because a component
went away for a very long time and came back again later
(in a way React doesn't even do right now), we safely recreate it and re-render
- trap the situation where a change is made to a tracked observable
between first render and commit (where we couldn't force an update
because we hadn't _been_ committed) and force a re-render
- more unit tests

* Fix renamed test file

When I renamed this file, I forgot the .test. suffix. D'oh.

* Extract tracking and cleanup logic out to separate file

* Update src/useObserver.ts

Co-Authored-By: RoystonS <royston@shufflebotham.org>

* Move some more tracking internals into the tracking code
@coveralls
Copy link

coveralls commented Aug 23, 2019

Coverage Status

Coverage decreased (-3.6%) to 95.098% when pulling 5655419 on next into d638b07 on master.

@danielkcz danielkcz marked this pull request as ready for review August 23, 2019 10:07
@xaviergonz
Copy link
Contributor

LGTM, just I think that there could be an optimization in the cleanup code.
If instead of a plain list the reactions were sorted on insertion (with priority set to cleanup time, via for example via a heap structure), then instead of traversing the whole list you could traverse the list from "soonest to latest to be cleaned" and break as soon as the time is already "not to be cleaned"

@danielkcz
Copy link
Collaborator Author

@xaviergonz I am sure it can be improved later. Such internal optimization won't be a breaking change most likely. But feel free to submit a PR if you like.

@xaviergonz
Copy link
Contributor

Btw, since it is now using tsdx I have the hunch .browserlistrc, tslint.config and jest config files are no longer needed

@xaviergonz
Copy link
Contributor

And probably it might be worth to add a .eslintrc.js with

module.exports = {
    extends: ["react-app", "prettier/@typescript-eslint"]
}

if not in the package json already

@danielkcz
Copy link
Collaborator Author

Btw, since it is now using tsdx I have the hunch .browserlistrc, tslint.config and jest config files are no longer needed

TSDX is just a build tool, the Jest config is still needed for sure, the .browserlistrc not sure how is that utilized actually. TSLint still works, but yea, I want to replace it with ESLint eventually, not sure if straight in 2.0, will see.

@mweststrate
Copy link
Member

Just checking in, was this waiting for something from my side? (Github notifications stopped working for me years ago)

@danielkcz
Copy link
Collaborator Author

@mweststrate No, I think this is mostly on me. I got kinda busy and forgot about this. Want to finish up #214 first and now also #226 should be figured out first.

src/useObserver.ts Outdated Show resolved Hide resolved
@danielkcz
Copy link
Collaborator Author

Alright, almost ready for release, just waiting for confirmation if the fix for #226 works.

@mweststrate
Copy link
Member

Given that the next branch solved some problems for others, I guess we can also cut a release and deal with any fallout later? I doubt we get more feedback without releasing.

@danielkcz
Copy link
Collaborator Author

danielkcz commented Nov 7, 2019

@mweststrate Well, given the Concurrent is now available for the library authors, I think it would be responsible to test it out properly with it before going full 2.0. However, right now the @testing-library is lacking behind and it's not really possible to run tests with Concurrent mode enabled.

@MohamedLamineAllal
Copy link

MohamedLamineAllal commented Nov 10, 2019

The build for the last version npm install mobx-react-lite@next. Have a problem considering typescript. index.d.ts is missing!
The current version have no problem however!
A feedback. And thank you a lot.
Screenshot from 2019-11-10 22-17-22
Screenshot from 2019-11-10 22-17-07

@danielkcz
Copy link
Collaborator Author

Thanks a lot for the feedback, not sure how could that happen. Fixed in 2.0.0-alpha.4

Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rebase it?

@danielkcz
Copy link
Collaborator Author

@auvipy Not before figuring out if there are some issues with the Concurrent mode.

@danielkcz danielkcz added this to the 2.0 milestone Feb 16, 2020
Kukkimonsuta and others added 4 commits February 16, 2020 16:47
* Preserve generics when using `observer`

* Remove any casting from statics as it's no longer needed

* Re-add overloads for explicitly specifying props type

* Allow for passing options without `forwardRef`

* Merge new `observer` overloads
@danielkcz danielkcz merged commit ef91cca into master Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet