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

Update refresh utils for Remix support #191

Merged
merged 2 commits into from
Jan 31, 2024
Merged

Update refresh utils for Remix support #191

merged 2 commits into from
Jan 31, 2024

Conversation

ArnaudBarre
Copy link
Member

@ArnaudBarre ArnaudBarre commented Jan 26, 2024

__beforePerformReactRefresh & __getReactRefreshIgnoredExports will not be part of semver until Remiix on Vite is stable (and without Fast Refresh related stuff being vendored).

I'll do the same on the Babel plugin once I've got some positif feedback from @pcattori

@@ -581,41 +581,60 @@ function debounce(fn, delay) {
};
}

const enqueueUpdate = debounce(performReactRefresh, 16);
const enqueueUpdate = debounce(() => {
window.__beforePerformReactRefresh?.();
Copy link
Member

Choose a reason for hiding this comment

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

I guess it'd nice to support registering multiple functions.
For example:

const hooks = []
window.__registerBeforePerformReactRefresh = (cb) => {
  hooks.push(cb)
}

// run in enqueueUpdate
hooks.forEach(hook => hook())

// framework code

window.__registerBeforePerformReactRefresh(() => {
  // do something that's needed
})

Another way to expose this functionality is to use an exported function:

import { registerBeforePerformReactRefreshHook } from '/@react-refresh-api'

registerBeforePerformReactRefreshHook(() => {
  // do something that's needed for that framework
})

I'm not sure which is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

This made me remind that Remix need this to be async
The second option is cleaner, but requires the remix client to passe through Vite pipeline or to handle base path, and I'm not sure it's the case for now

src/refresh-runtime.js Outdated Show resolved Hide resolved
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

If this interface meets the needs of the remix, it looks good to me.

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