Skip to content
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

Fix #3671: observer + StrictMode #3673

Closed
wants to merge 15 commits into from
Closed

Conversation

urugator
Copy link
Collaborator

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Mar 28, 2023

🦋 Changeset detected

Latest commit: 36eeb2f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mobx-react-lite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@urugator
Copy link
Collaborator Author

Changes in render counts in deprecated tests are caused by React 18.0.0 -> 18.2.0. They were failing with pevious (pre 4.*) impl as well. See #3601 (comment)

@mweststrate
Copy link
Member

Put up a draft that avoids making props / state observable, so that it plays better with Reacts internals. This diff shows a) alternative patterns and b) a way to detect the otherwise now broken usage of props / state inside reactions / computed. 94d78da

@urugator
Copy link
Collaborator Author

urugator commented May 28, 2023

props/state/context are no longer observable.
Accessing props/state/context in different derivation than current render throws.
Fixed #3691

TODO:
Documentation.

Tests demonstrating workaround.

Shouldn't we throw instead?

if (componentClass[isMobXReactObserverSymbol]) {
        const displayName = getDisplayName(componentClass)
        console.warn(
            `The provided component class (${displayName})
                has already been declared as an observer component.`
        )
} else {
       componentClass[isMobXReactObserverSymbol] = true
}

Extending observer component doesn't seem to be supported, should we add an explicit check?

@mweststrate
Copy link
Member

Shouldn't we throw instead?

Sounds good to me!

Extending observer component doesn't seem to be supported, should we add an explicit check?

Good idea, nails down that semantics at least.

What can I do to help further push this change :) ?

@urugator
Copy link
Collaborator Author

What can I do to help further push this change :) ?

Documenting the non-reactive props change would be a big help :)

@urugator
Copy link
Collaborator Author

urugator commented Jul 1, 2023

Added tests demonstrating observable props/state/context workaround.

Applying observer multiple times now throws.

Explicit check for extending observer component turned out to be impossible without an access to observer base class constructor. Added note to documentation instead.

What would be nice to have, but I personally don't plan to do at the moment (help welcome):

  • Test or sample app that integrates multiple functional / class components + strict mode and combines multiple techniques/approaches.
  • Nightly releases, so these "bigger" changes could be tested on larger existing codebases before releasing major for production use.

What should be done next:

@mweststrate mweststrate mentioned this pull request Jul 9, 2023
@mweststrate
Copy link
Member

mweststrate commented Jul 9, 2023

See #3718 as I don't think I can push to origin urugator.

Will continue on remaining items coming days.

@mweststrate
Copy link
Member

@urugator some items are still open, but how'd you feel about releasing the current state? Since I don't entirely trust the current state of releases / changelog, I'm tempted to trigger a release, and then verify is everything ended up well and roll forward if anything went south.

@urugator
Copy link
Collaborator Author

go for it

@mweststrate
Copy link
Member

Merged, via #3718. Thanks for all the hard work here once again @urugator! (Feel free to invoice).

@mweststrate
Copy link
Member

@urugator just noticed no mobx-react-lite release was triggered. Should this have emitted a major there as well?

@mweststrate
Copy link
Member

Ah no, I think it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants