fix(Example): add ESLint rule to enforce top-level component exports in SFT and CIT#3959
Open
fix(Example): add ESLint rule to enforce top-level component exports in SFT and CIT#3959
Conversation
also apply it to SFT and CIT
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a local ESLint rule to enforce that top-level React component declarations in the single-feature-tests (SFT) and component-integration-tests (CIT) suites are exported, addressing Fast Refresh remounting caused by Metro module boundary heuristics.
Changes:
- Introduce a local ESLint plugin (
local-rules) with arequire-top-level-exportsrule. - Add ESLint configuration under
apps/src/teststo apply the rule to SFT and CIT. - Update SFT/CIT files to export their top-level components (e.g.,
ConfigScreen,TestScreen,HomeScreen, etc.).
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/src/tests/single-feature-tests/tabs/test-tabs-tab-bar-minimize-behavior-ios/index.tsx | Export top-level tab test components. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-tab-bar-layout-direction/index.tsx | Export top-level config component. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-tab-bar-hidden/index.tsx | Export top-level config component. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-tab-bar-controller-mode-ios/index.tsx | Export top-level tab test components. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-tab-bar-color-scheme/index.tsx | Export top-level tab test components. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-stale-update-rejection.tsx | Export top-level components in the scenario. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-simple-nav.tsx | Export top-level components in the scenario. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-prevent-native-selection/index.tsx | Export top-level components in the scenario. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-more-navigation-controller.tsx | Export top-level components in the scenario. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-ime-insets.tsx | Export top-level config component. |
| apps/src/tests/single-feature-tests/tabs/test-tabs-appearance-defined-by-selected-tab.tsx | Export top-level tab screen component. |
| apps/src/tests/single-feature-tests/tabs/tabs-screen-orientation.tsx | Export top-level config component. |
| apps/src/tests/single-feature-tests/tabs/override-scroll-view-content-inset.tsx | Export top-level tab/content components. |
| apps/src/tests/single-feature-tests/tabs/bottom-accessory-layout.tsx | Export top-level accessory/config components. |
| apps/src/tests/single-feature-tests/stack-v5/test-stack-subviews-android/index.tsx | Export top-level stack setup/config components. |
| apps/src/tests/single-feature-tests/stack-v5/test-stack-simple-nav/index.tsx | Export top-level stack components/screens. |
| apps/src/tests/single-feature-tests/stack-v5/test-stack-back-button-android/index.tsx | Export top-level stack screens/controls. |
| apps/src/tests/single-feature-tests/stack-v5/test-animation-android.tsx | Export top-level stack screens/setup. |
| apps/src/tests/single-feature-tests/stack-v5/prevent-native-dismiss-single-stack.tsx | Export top-level stack screens/helpers. |
| apps/src/tests/single-feature-tests/stack-v5/prevent-native-dismiss-nested-stack.tsx | Export top-level nested stack screens/helpers. |
| apps/src/tests/single-feature-tests/stack-v4/stack-v4-orientation.tsx | Export top-level config component. |
| apps/src/tests/single-feature-tests/split/test-top-column-for-collapsing.tsx | Export top-level split column component. |
| apps/src/tests/single-feature-tests/split/test-command-show-column.tsx | Export top-level split column component. |
| apps/src/tests/single-feature-tests/scroll-view-marker/test-svm-configures-scroll-view.tsx | Export top-level content screen component. |
| apps/src/tests/single-feature-tests/index.tsx | Export top-level HomeScreen. |
| apps/src/tests/eslint-plugin-local-rules/require-top-level-exports.js | Implement local ESLint rule logic. |
| apps/src/tests/eslint-plugin-local-rules/package.json | Define local plugin package metadata. |
| apps/src/tests/eslint-plugin-local-rules/index.js | Export plugin rules entrypoint. |
| apps/src/tests/component-integration-tests/orientation/orientation-tabs-in-stack.tsx | Export top-level orientation test components. |
| apps/src/tests/component-integration-tests/orientation/orientation-stack-in-tabs.tsx | Export top-level orientation test components. |
| apps/src/tests/component-integration-tests/index.tsx | Export top-level HomeScreen. |
| apps/src/tests/.eslintrc.js | Apply local rule to SFT/CIT via overrides. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+51
to
+63
| if (stmt.type === 'VariableDeclaration' && stmt.declarations.length === 1) { | ||
| const decl = stmt.declarations[0]; | ||
| const name = decl.id?.name; | ||
| if ( | ||
| name && | ||
| isPascalCase(name) && | ||
| decl.init && | ||
| (decl.init.type === 'ArrowFunctionExpression' || | ||
| decl.init.type === 'FunctionExpression') | ||
| ) { | ||
| return name; | ||
| } | ||
| } |
Comment on lines
+1
to
+14
| const path = require('path'); | ||
| const Module = require('module'); | ||
|
|
||
| const pluginPath = require.resolve( | ||
| path.join(__dirname, 'eslint-plugin-local-rules'), | ||
| ); | ||
| const originalResolve = Module._resolveFilename; | ||
| Module._resolveFilename = function (request, ...args) { | ||
| if (request === 'eslint-plugin-local-rules') { | ||
| return pluginPath; | ||
| } | ||
| return originalResolve.call(this, request, ...args); | ||
| }; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a local ESLint rule
require-top-level-exportsto ensure that all top-level React component declarations in our test suites are exported.This approach fixes an issue with Fast Refresh where some of the unexported components were being fully remounted instead of seamlessly updated. This behavior is tied to the Metro bundler's specification regarding module boundaries and state preservation. By ensuring all top-level components are explicitly exported, Metro can properly track them, which fixes the remounting issue and allows Fast Refresh to work as intended.
Changes
Before & after - visual documentation
Before
without.exports.mov
After
with.exports.mov
Test plan
Make sure that updating components of single-feature and component-integration tests triggers a correct Fast Refresh.
Checklist