-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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
Warn when second argument to render is null and document.body is null as well #2448
Comments
👍 I think many don't really understand what |
This sounds vaguely reasonable, but I think we're going to do #3211 instead so I'll close this. |
This was referenced Jul 8, 2022
josephsavona
added a commit
that referenced
this issue
May 15, 2024
See discussion on #2448 for full context. In the new `@enablePreserveExistingMemoizationGuarantees` mode, the goal is to preserve the existing referential equality guarantees from the original code. #2448 lays the groundwork by explicitly marking the _output_ of each useMemo block as memoized, hinting to the compiler that the value cannot subsequently change. This ensures the mutable range doesn't extend _later_, possibly overlapping a hook call and causing memoization to gett pruned. This PR fixes the other direction. There are cases where free variables referenced in the useMemo block could have been inferred as mutated, which could then extend the _start_ of the range earlier past a hook: ```javascript const foo = createObject(); useBar(); const baz = useMemo(() => { const baz = createObject(); maybeMutate(foo, baz); return baz; }, [foo]); ``` Here the compiler would infer that both `baz` and `foo` are mutable at the `maybeMutate()` call, grouping them in the same scope. But that scope would span the `useBar()` call, and be pruned, meaning that `baz` went unmemoized. However, useMemo blocks shouldn't be mutating free variables. Only variables newly created within the useMemo block should be mutable. So this PR extends the feature to treat all free variables referenced in a useMemo block as frozen as of the block itself.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Too often I run into this:
when making a new project / example.
The reason is I'm passing
document.body
but React's script is inhead
and body doesn't exist yet.This is very common problem as I observed for beginners, as they tend to put their scripts in
head
but React samples usedocument.body
as mounting point.The real problem here is the message: you wouldn't believe that
document.body
"is not a DOM element" and assume something else is wrong, without realizing it may be empty at the time.I suggest we show a different, more specific warning when second argument is
null
anddocument.body
isnull
. Something like "Target container is null. Are you trying to mount todocument.body
before it is ready?"The text was updated successfully, but these errors were encountered: