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

Add autoStart feature #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

MonicaOlejniczak
Copy link
Collaborator

@MonicaOlejniczak MonicaOlejniczak commented May 17, 2021

These changes introduce a global autoStart configuration option, that when enabled, will schedule and manage lazy component loaders automatically. This ultimately removes the need to have useLazyPhase and will close #67.

Changes

  • Add autoStart global configuration, and associated documentation
  • Add an internal useScheduler hook and associated tests, which is used in the client lazy component
  • Introduce @testing-library/react-hooks to test the scheduler
  • Handle autoStart configuration in the client lazy component, by scheduling the deferred task inside of a useLayoutEffect (more discussion and rationale here: In StrictMode, the useState() initializer function is called twice, but one of the results is discarded facebook/react#20090 (comment)), and add corresponding tests
  • Add more lazy client unit tests, which captured an issue with the preload deferred logic with retry (fixed in the PR)
  • Move client fallback logic to a custom hook, with the existing placeholders
  • Test autoStart in root and LazyWait integration tests

Notes

  • autoStart handling is performed in the component render, which ensures that the behaviour is consistent in the case where a lazy* factory is imported and evaluated before init. So long as the init is called before React render, this should be obey the rule of hooks and work as expected.

@MonicaOlejniczak MonicaOlejniczak force-pushed the feature/auto-start-phases branch 2 times, most recently from 86e5226 to cab7ddb Compare May 19, 2021 05:33
@albertogasparin
Copy link
Collaborator

Sorry this never got merged... Anyway this behaviour plays well with React 18 Suspense + concurrent mode, as deferred components should not remain dead for long as might cause hydration to break, so we should hydrate them asap (but still makes sense to have some priorities).

Also, I think we should make autoStart work without a configuration. Basically we enable it by default, but if somewhere we use useLazyPhase, we turn it off. Should be doable as the component with useLazyPhase should run before afterPaint components are scheduled to load, what do you think?

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.

Auto start phases if consumer does not hook into phase manager
2 participants