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

[Flight] Encode the name of a function as an object property #30325

Merged
merged 1 commit into from
Jul 13, 2024

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Jul 12, 2024

Unfortunately, Firefox doesn't include the name of a function in stack traces if you set it as either .name or .displayName at runtime. Only if you include it declarative.

We also can't include it into a named function expression because not all possible names are expressible declaratively. E.g. spaces or punctuations.

However, we can express any name if it's an object property and since object properties now give their name declarative to the function defined inside of them, we can declaratively express any name this way.

@sebmarkbage sebmarkbage requested review from gnoff and eps1lon July 12, 2024 21:32
Copy link

vercel bot commented Jul 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 9:46pm

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jul 12, 2024
// We generate code where the call is at the line and column of the server executed code.
// This allows us to use the original source map as the source map of this fake file to
// point to the original source.
let code;
if (line <= 1) {
code = '_=>' + ' '.repeat(col < 4 ? 0 : col - 4) + '_()\n' + comment;
const minSize = encodedName.length + 8;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We cannot model a call on the first row with a column less than this.

Copy link
Collaborator

@gnoff gnoff left a comment

Choose a reason for hiding this comment

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

Clever

@sebmarkbage sebmarkbage merged commit 8b08e99 into facebook:main Jul 13, 2024
185 checks passed
@@ -1931,7 +1945,7 @@ function createFakeFunction<T>(
let fn: FakeFunction<T>;
try {
// eslint-disable-next-line no-eval
fn = (0, eval)(code);
fn = (0, eval)(code)[name];
} catch (x) {
// If eval fails, such as if in an environment that doesn't support it,
// we fallback to creating a function here. It'll still have the right
Copy link
Collaborator

Choose a reason for hiding this comment

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

no longer true?

felixshiftellecon added a commit to felixshiftellecon/react that referenced this pull request Jul 24, 2024
…k#30325)

Unfortunately, Firefox doesn't include the name of a function in stack
traces if you set it as either `.name` or `.displayName` at runtime.
Only if you include it declarative.

We also can't include it into a named function expression because not
all possible names are expressible declaratively. E.g. spaces or
punctuations.

However, we can express any name if it's an object property and since
object properties now give their name declarative to the function
defined inside of them, we can declaratively express any name this way.
felixshiftellecon added a commit to felixshiftellecon/react that referenced this pull request Jul 24, 2024
…k#30325)

Unfortunately, Firefox doesn't include the name of a function in stack
traces if you set it as either `.name` or `.displayName` at runtime.
Only if you include it declarative.

We also can't include it into a named function expression because not
all possible names are expressible declaratively. E.g. spaces or
punctuations.

However, we can express any name if it's an object property and since
object properties now give their name declarative to the function
defined inside of them, we can declaratively express any name this way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants