Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ function validateNoRefAccessInRenderImpl(
);
break;
}
case 'TypeCastExpression': {
env.set(
instr.lvalue.identifier.id,
env.get(instr.value.value.identifier.id) ??
refTypeOfType(instr.lvalue),
);
break;
}
case 'LoadContext':
case 'LoadLocal': {
env.set(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

## Input

```javascript
import {useRef} from 'react';

function useArrayOfRef() {
const ref = useRef(null);
const callback = value => {
ref.current = value;
};
return [callback] as const;
}

export const FIXTURE_ENTRYPOINT = {
fn: () => {
useArrayOfRef();
return 'ok';
},
params: [{}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
import { useRef } from "react";

function useArrayOfRef() {
const $ = _c(1);
const ref = useRef(null);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
const callback = (value) => {
ref.current = value;
};

t0 = [callback];
$[0] = t0;
} else {
t0 = $[0];
}
return t0 as const;
}

export const FIXTURE_ENTRYPOINT = {
fn: () => {
useArrayOfRef();
return "ok";
},

params: [{}],
};

```

### Eval output
(kind: ok) "ok"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {useRef} from 'react';

function useArrayOfRef() {
const ref = useRef(null);
const callback = value => {
ref.current = value;
};
return [callback] as const;
}

export const FIXTURE_ENTRYPOINT = {
fn: () => {
useArrayOfRef();
return 'ok';
},
params: [{}],
};
35 changes: 24 additions & 11 deletions packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let waitForPaint;
let assertLog;
let waitForThrow;
let act;
let assertConsoleErrorDev;

describe('ReactCache', () => {
beforeEach(() => {
Expand All @@ -39,6 +40,7 @@ describe('ReactCache', () => {
assertLog = InternalTestUtils.assertLog;
waitForThrow = InternalTestUtils.waitForThrow;
waitForPaint = InternalTestUtils.waitForPaint;
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
act = InternalTestUtils.act;

TextResource = createResource(
Expand Down Expand Up @@ -190,20 +192,31 @@ describe('ReactCache', () => {
);

if (__DEV__) {
await expect(async () => {
await waitForAll([
'App',
'Loading...',

...(gate('enableSiblingPrerendering') ? ['App'] : []),
]);
}).toErrorDev([
await waitForAll([
'App',
'Loading...',

...(gate('enableSiblingPrerendering') ? ['App'] : []),
]);
assertConsoleErrorDev([
'Invalid key type. Expected a string, number, symbol, or ' +
"boolean, but instead received: [ 'Hi', 100 ]\n\n" +
'To use non-primitive values as keys, you must pass a hash ' +
'function as the second argument to createResource().',

...(gate('enableSiblingPrerendering') ? ['Invalid key type'] : []),
'function as the second argument to createResource().\n' +
' in App (at **)' +
(gate(flags => flags.enableOwnerStacks)
? ''
: '\n in Suspense (at **)'),

...(gate('enableSiblingPrerendering')
? [
'Invalid key type. Expected a string, number, symbol, or ' +
"boolean, but instead received: [ 'Hi', 100 ]\n\n" +
'To use non-primitive values as keys, you must pass a hash ' +
'function as the second argument to createResource().\n' +
' in App (at **)',
]
: []),
]);
} else {
await waitForAll([
Expand Down
Loading
Loading