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

Adding better support for hooks related to time-slicing(concurrent) ⏲️ #3760

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sanjaiyan-dev
Copy link

@sanjaiyan-dev sanjaiyan-dev commented Oct 9, 2022

Adding better support for concurrency⏲️

Running the concurrent task in idle period using window.requestIdleCallback.

  • Adding support for running the concurrental tasks by running it in idle period without blocking other urgent functions. (including scroll, touch, click...)
  • Mocking useTransition behaviour using useState hook.

Extremely sorry if I made any mistakes :(

@sanjaiyan-dev sanjaiyan-dev changed the title Running the concurrent task in idle period ⏲️ Better support for hooks related to _time-slicing_ ⏲️ Oct 9, 2022
@sanjaiyan-dev sanjaiyan-dev changed the title Better support for hooks related to _time-slicing_ ⏲️ Better support for hooks related to time-slicing ⏲️ Oct 9, 2022
@sanjaiyan-dev sanjaiyan-dev changed the title Better support for hooks related to time-slicing ⏲️ Better support for hooks related to time-slicing(concurrent) ⏲️ Oct 9, 2022
@sanjaiyan-dev sanjaiyan-dev changed the title Better support for hooks related to time-slicing(concurrent) ⏲️ Adding support for hooks related to time-slicing(concurrent) ⏲️ Oct 9, 2022
@sanjaiyan-dev sanjaiyan-dev changed the title Adding support for hooks related to time-slicing(concurrent) ⏲️ Adding better support for hooks related to time-slicing(concurrent) ⏲️ Oct 9, 2022
@sanjaiyan-dev sanjaiyan-dev marked this pull request as draft October 9, 2022 19:38
@sanjaiyan-dev sanjaiyan-dev marked this pull request as ready for review October 9, 2022 19:38
Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

This is a great start 🎉 Left some comments, let me know what you think.

compat/src/index.js Outdated Show resolved Hide resolved
return [false, startTransition];
const [isTransitionPending, setIsTransitionPending] = useState(false);

const startTransitionFunction = (cb) => {
Copy link
Member

Choose a reason for hiding this comment

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

The function identity will change with every render. Let's find a way to keep the reference stable.

Copy link
Author

Choose a reason for hiding this comment

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

using use callback have any effect on it ?

The function identity will change with every render. Let's find a way to keep the reference stable.

Comment on lines 37 to 46
const requestIdleCallbackPreact =
(typeof self !== "undefined" &&
self.requestIdleCallback &&
self.requestIdleCallback.bind(window)) ||
function (cb) {
return queueMicrotask(() => {
cb();
});
};

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we need to bind the this value explicitly. Maybe we can simplify this a bit?

Suggested change
const requestIdleCallbackPreact =
(typeof self !== "undefined" &&
self.requestIdleCallback &&
self.requestIdleCallback.bind(window)) ||
function (cb) {
return queueMicrotask(() => {
cb();
});
};
const requestIdleCallbackPreact =
typeof requestIdleCallback === 'function'
? requestIdleCallback
: queueMicrotask;

Copy link
Author

Choose a reason for hiding this comment

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

Hi @marvinhagemeister , Currently i updated to setTimeout since it need to be cleared in unmount. (Can you please help me with it)

@sanjaiyan-dev
Copy link
Author

🤔

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.

None yet

2 participants