Skip to content

Commit

Permalink
[expo-router] prevent generating types in a loop (expo#29157)
Browse files Browse the repository at this point in the history
# Why

Likely fixes expo#28248

Several people on
[Discord](https://discord.com/channels/695411232856997968/1241672799710347345/1242593907657801738)
reported that after working on a newly created project, it keeps
refreshing after a while.

It's reliably reproducible with:
```
npx create-expo-app
npm run ios
npm run reset-project
```

<!--
Please describe the motivation for this PR, and link to relevant GitHub
issues, forums posts, or feature requests.
-->

# How

The `throttle` function used for `regenerateDeclarations` didn't reset
`shouldRunAgain` back to false, so it actually ends up calling the
function in a loop.

<!--
How did you build this feature or fix this bug and why?
-->

# Test Plan

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

Try the steps to reproduce with this fix applied - it no longer runs the
function in a loop.

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
  • Loading branch information
kadikraman authored May 27, 2024
1 parent da05e47 commit bfc2e7e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/expo-router/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### 🐛 Bug fixes

- Fix generating types in a loop ([#29157](https://github.com/expo/expo/pull/29157) by [@kadikraman](https://github.com/kadikraman))

### 💡 Others

## 3.5.14 — 2024-05-15
Expand Down
1 change: 1 addition & 0 deletions packages/expo-router/build/typed-routes/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-router/build/typed-routes/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/expo-router/src/typed-routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function throttle<T extends (...args: any[]) => any>(fn: T, interval: number) {
timerId = setTimeout(() => {
timerId = null; // reset the timer so next call will be executed
if (shouldRunAgain) {
shouldRunAgain = false;
run(...args); // call the function again
}
}, interval);
Expand Down

0 comments on commit bfc2e7e

Please sign in to comment.