Skip to content

Conversation

@josephsavona
Copy link
Member

For now we just reject all calls of impure functions, and the validation is off by default. Going forward we can make this more precise and only reject impure functions called during render.

Note that I was intentionally imprecise in the return type of these functions in order to avoid changing output of existing code. We lie to the compiler and say that Date.now, performance.now, and Math.random return unknown mutable objects rather than primitives. Once the validation is complete and vetted we can switch this to be more precise.

…g render

For now we just reject all calls of impure functions, and the validation is off by default. Going forward we can make this more precise about impure functions called during render.

Note that I was intentionaly imprecise in the return type of these functions in order to avoid changing output of existing code. We lie to the compiler and say that Date.now, performance.now, and Math.random return unknown mutable objects rather than primitives. Once the validation is complete and vetted we can switch this to be more precise.
@vercel
Copy link

vercel bot commented Jan 2, 2025

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

Name Status Preview Comments Updated (UTC)
react-compiler-playground ❌ Failed (Inspect) Jan 2, 2025 8:10pm

[
'Date',
addObject(DEFAULT_SHAPES, 'Date', [
// Static methods (TODO)
Copy link
Member

Choose a reason for hiding this comment

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

new Date() too (no args)

@PeteVanG

This comment was marked as spam.

@kassens
Copy link
Member

kassens commented Jan 3, 2025

This is only checking the top level instructions (no closures) if I read this right? Seems okay, doing more seems like it'd be easy to cause false positives.

Copy link
Contributor

@mofeiZ mofeiZ left a comment

Choose a reason for hiding this comment

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

Nice, let's go!!

@josephsavona josephsavona merged commit 7f3826e into facebook:main Jan 17, 2025
18 of 19 checks passed
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.

5 participants