Skip to content

Commit

Permalink
useFormState fix: action -> target (#27309)
Browse files Browse the repository at this point in the history
I mixed these attributes up in
#27302
  • Loading branch information
acdlite committed Aug 30, 2023
1 parent ddff504 commit 2fba484
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('ReactFlightDOMForm', () => {

// @gate enableFormActions
// @gate enableAsyncActions
it("useFormState can change the action's target with the `permalink` argument", async () => {
it('useFormState can change the action URL with the `permalink` argument', async () => {
const serverAction = serverExports(function action(prevState) {
return {state: prevState.count + 1};
});
Expand Down Expand Up @@ -386,7 +386,7 @@ describe('ReactFlightDOMForm', () => {
const span = container.getElementsByTagName('span')[0];
expect(span.textContent).toBe('Count: 1');

expect(form.target).toBe('/permalink');
expect(form.action).toBe('http://localhost/permalink');
});

// @gate enableFormActions
Expand Down Expand Up @@ -427,6 +427,6 @@ describe('ReactFlightDOMForm', () => {
const span = container.getElementsByTagName('span')[0];
expect(span.textContent).toBe('Count: 1');

expect(form.target).toBe('/permalink');
expect(form.action).toBe('http://localhost/permalink');
});
});
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ function useFormState<S, P>(
dispatch.$$FORM_ACTION = (prefix: string) => {
// $FlowIgnore[prop-missing]
const metadata: ReactCustomFormAction = boundAction.$$FORM_ACTION(prefix);
// Override the target URL
// Override the action URL
if (permalink !== undefined) {
if (__DEV__) {
checkAttributeStringCoercion(permalink, 'target');
}
metadata.target = permalink + '';
metadata.action = permalink + '';
}
return metadata;
};
Expand Down

0 comments on commit 2fba484

Please sign in to comment.