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

[router]: Fix fast refresh on layout files #29977

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

Conversation

marklawlor
Copy link
Contributor

Why

Fix Fast Refresh on _layout files that export unstable_settings and/or ErrorBoundary.

How

Metro's FastRefresh implementation has a set of rule that Expo Router does not follow causing full app reloads.

Next.js is a similar framework to Expo Router which has resolved the issue in a similar fashion. In the Next.js implementation they

  • Use Babel to rename the exports to prevent false positive (e.g getStaticProps/getStaticPaths are bundled into a __N_SSG export`
  • Replace ReactRefresh with their own extended version

While the Next.js solution is more robust, I believe this solution is simple enough for our current needs.

Possible additional changes:

  • tag ErrorBoundary and the ctx export with a Symbol and use that for isLikelyComponentType detection
  • Ensure unstable_settings only exists on a module with a default export
  • Mutate unstable_settings during getRoutes with a Symbol and use that for isLikelyComponentType detection

Test Plan

npx create-expo-app app

  • Set some local state (e.g going to a tab)
  • Modify the _layout file

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Jun 24, 2024
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Jun 24, 2024
@marklawlor
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint compatible bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants