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(react-virtual): handle scrollElement cleanup after HMR #820

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

hophiphip
Copy link
Contributor

@hophiphip hophiphip commented Aug 30, 2024

When HMR is triggered useEffect cleanup function will call function returned from instance._didMount().
This will set scrollElement to null and Virtualizer will stop working.

I added an additional check if scrollElement is null and if it is - call instance._willUpdate().

This PR resolves #750.

@hophiphip hophiphip changed the title fix: handle scrollElement cleanup on HMR fix: handle scrollElement cleanup after HMR Aug 30, 2024
@hophiphip hophiphip changed the title fix: handle scrollElement cleanup after HMR fix(react-virtual): handle scrollElement cleanup after HMR Aug 30, 2024
@rameshx
Copy link

rameshx commented Nov 27, 2024

@piecyk can this be merged? I think this fixes the white space issue after HMR

@Innei
Copy link

Innei commented Dec 9, 2024

@tannerlinsley Hey, can you take a look at this PR? Can it be merged?

Comment on lines 45 to 49
React.useEffect(() => {
if (!instance.scrollElement) {
instance._willUpdate()
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think better would be to change the useEffect to useIsomorphicLayoutEffect

Suggested change
React.useEffect(() => {
if (!instance.scrollElement) {
instance._willUpdate()
}
useIsomorphicLayoutEffect(() => {

then order will be correct

instance._didMount, cleanup
instance._willUpdate, cleanup
instance._didMount
instance._willUpdate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, interesting, was there a reason useEffect was used instead of useIsomorphicLayoutEffect since the beginning?

Copy link
Collaborator

@piecyk piecyk Dec 9, 2024

Choose a reason for hiding this comment

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

Overall when possible useEffect should preferred, there was no clear reason till now ot use useIsomorphicLayoutEffect imho.

useLayoutEffect is a version of useEffect that fires before the browser repaints the screen.

As this is called in limited way changing it to layout effect should be fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hophiphip please update the PR, then we can merge it! Thanks for looking into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@piecyk, updated PR

Copy link

nx-cloud bot commented Dec 9, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5ab9a3b. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

Copy link

pkg-pr-new bot commented Dec 9, 2024

Open in Stackblitz

More templates

@tanstack/angular-virtual

npm i https://pkg.pr.new/@tanstack/angular-virtual@820

@tanstack/lit-virtual

npm i https://pkg.pr.new/@tanstack/lit-virtual@820

@tanstack/solid-virtual

npm i https://pkg.pr.new/@tanstack/solid-virtual@820

@tanstack/react-virtual

npm i https://pkg.pr.new/@tanstack/react-virtual@820

@tanstack/svelte-virtual

npm i https://pkg.pr.new/@tanstack/svelte-virtual@820

@tanstack/virtual-core

npm i https://pkg.pr.new/@tanstack/virtual-core@820

@tanstack/vue-virtual

npm i https://pkg.pr.new/@tanstack/vue-virtual@820

commit: 5ab9a3b

@piecyk piecyk merged commit 49df294 into TanStack:main Dec 9, 2024
5 checks passed
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.

HMR (live reload, fast refresh) broke render in React
4 participants