Skip to content

Fix stateful regex bug in benchmark detection#56423

Closed
rubennorte wants to merge 1 commit intofacebook:mainfrom
rubennorte:export-D100603612
Closed

Fix stateful regex bug in benchmark detection#56423
rubennorte wants to merge 1 commit intofacebook:mainfrom
rubennorte:export-D100603612

Conversation

@rubennorte
Copy link
Copy Markdown
Contributor

Summary:
Changelog: [internal]

The FANTOM_BENCHMARK_FILENAME_RE and FANTOM_BENCHMARK_SUITE_RE regexes used the g (global) flag, which makes .test() stateful — it preserves lastIndex between calls. When getFantomTestConfigs is called for multiple test files in the same process, the stale lastIndex from a previous successful match causes .test() to miss the match on the next file, returning false. This results in benchmark files intermittently getting the default dev config (isJsOptimized: false, dev: true), causing them to fail at runtime with "Benchmarks should not be run in development mode".

Removes the g flag from both regexes since they are used with .test() across different strings and should be stateless.

Differential Revision: D100603612

Summary:
Changelog: [internal]

The `FANTOM_BENCHMARK_FILENAME_RE` and `FANTOM_BENCHMARK_SUITE_RE` regexes used the `g` (global) flag, which makes `.test()` stateful — it preserves `lastIndex` between calls. When `getFantomTestConfigs` is called for multiple test files in the same process, the stale `lastIndex` from a previous successful match causes `.test()` to miss the match on the next file, returning `false`. This results in benchmark files intermittently getting the default dev config (`isJsOptimized: false`, `dev: true`), causing them to fail at runtime with "Benchmarks should not be run in development mode".

Removes the `g` flag from both regexes since they are used with `.test()` across different strings and should be stateless.

Differential Revision: D100603612
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 13, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 13, 2026

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100603612.

@meta-codesync meta-codesync bot closed this in 4bdfaf2 Apr 13, 2026
@facebook-github-tools facebook-github-tools bot added the Merged This PR has been merged. label Apr 13, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 13, 2026

This pull request has been merged in 4bdfaf2.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @rubennorte in 4bdfaf2

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants