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
6 changes: 3 additions & 3 deletions packages/react-server-dom-esm/src/ReactFlightESMReferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export function registerServerReference<T>(
): ServerReference<T> {
return Object.defineProperties((reference: any), {
$$typeof: {value: SERVER_REFERENCE_TAG},
$$id: {value: id + '#' + exportName},
$$bound: {value: null},
bind: {value: bind},
$$id: {value: id + '#' + exportName, configurable: true},
$$bound: {value: null, configurable: true},
bind: {value: bind, configurable: true},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ export function registerServerReference<T>(
): ServerReference<T> {
return Object.defineProperties((reference: any), {
$$typeof: {value: SERVER_REFERENCE_TAG},
$$id: {value: exportName === null ? id : id + '#' + exportName},
$$bound: {value: null},
bind: {value: bind},
$$id: {
value: exportName === null ? id : id + '#' + exportName,
configurable: true,
},
$$bound: {value: null, configurable: true},
bind: {value: bind, configurable: true},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ export function registerServerReference<T>(
): ServerReference<T> {
return Object.defineProperties((reference: any), {
$$typeof: {value: SERVER_REFERENCE_TAG},
$$id: {value: exportName === null ? id : id + '#' + exportName},
$$bound: {value: null},
bind: {value: bind},
$$id: {
value: exportName === null ? id : id + '#' + exportName,
configurable: true,
},
$$bound: {value: null, configurable: true},
bind: {value: bind, configurable: true},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,58 @@ describe('ReactFlightDOMBrowser', () => {
}
});

it('can use the same function twice as a server action', async () => {
let actionProxy1;
let actionProxy2;

function Client({action1, action2}) {
actionProxy1 = action1;
actionProxy2 = action2;
return 'Click Me';
}

function greet(text) {
return 'Hello ' + text;
}

const ServerModule = serverExports({
greet,
greet2: greet,
});
const ClientRef = clientExports(Client);

const stream = ReactServerDOMServer.renderToReadableStream(
<ClientRef action1={ServerModule.greet} action2={ServerModule.greet2} />,
webpackMap,
);

const response = ReactServerDOMClient.createFromReadableStream(stream, {
async callServer(ref, args) {
const body = await ReactServerDOMClient.encodeReply(args);
return callServer(ref, body);
},
});

function App() {
return use(response);
}

const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<App />);
});
expect(container.innerHTML).toBe('Click Me');
expect(typeof actionProxy1).toBe('function');
expect(actionProxy1).not.toBe(greet);

// TODO: Ideally flight would be encoding this the same.
expect(actionProxy1).not.toBe(actionProxy2);

const result = await actionProxy1('world');
expect(result).toBe('Hello world');
});

it('supports Float hints before the first await in server components in Fiber', async () => {
function Component() {
return <p>hello world</p>;
Expand Down