-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
fix: edge case when rsa depends on another rsa #785
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b4fcfa5
fix: edge case when rsa depends on another rsa
himself65 2f720a4
test: add test case
himself65 4a5266d
fix: remove debugger
himself65 9900d74
fix: lint
himself65 adfeec3
fix: test
himself65 93efe90
refactor: dev / prod
himself65 ac345cf
Merge branch 'main' into himself65/20240709/action
himself65 6d46f2e
fix: remove unused
himself65 4db6361
Merge remote-tracking branch 'origin/himself65/20240709/action' into …
himself65 4132469
fix: remove console.log
himself65 944b44c
fix: loadModule
himself65 32ea016
fix: deps
himself65 4c56b7d
Merge branch 'main' into himself65/20240709/action
himself65 d037dc3
does this work? maybe not
dai-shi c45f2cc
revert dev-server change
dai-shi 65c8c2d
Revert "revert dev-server change"
dai-shi 93320d0
remove diff
dai-shi ed9d708
Revert "Revert "revert dev-server change""
dai-shi e660f9d
fix: second try
himself65 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "ai", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"description": "Vercel AI mockup", | ||
"exports": { | ||
"./rsc": { | ||
"types": "./src/index.d.ts", | ||
"react-server": "./src/server.js", | ||
"import": "./src/client.js" | ||
} | ||
}, | ||
"devDependencies": { | ||
"react-dom": "^18", | ||
"react-server-dom-webpack": "18.3.0-canary-eb33bd747-20240312" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18 || ^19" | ||
}, | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use client'; | ||
import { useActions } from './shared.js'; | ||
|
||
export { useActions }; | ||
|
||
export function createAI() { | ||
throw new Error('You should not call createAI in the client side'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { ReactNode } from 'react'; | ||
|
||
declare function createAI( | ||
actions: Record<string, (...args: any[]) => any>, | ||
): (props: { children: ReactNode }) => ReactNode; | ||
|
||
declare function useActions(): Record<string, any>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use server'; | ||
import { InternalProvider } from './shared.js'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
|
||
async function innerAction({ action }, state, ...args) { | ||
'use server'; | ||
return action(...args); | ||
} | ||
|
||
function wrapAction(action, options) { | ||
return innerAction.bind(null, { action, options }); | ||
} | ||
|
||
export function createAI(actions) { | ||
const wrappedActions = {}; | ||
for (const name in actions) { | ||
wrappedActions[name] = wrapAction(actions[name]); | ||
} | ||
return function AI(props) { | ||
return jsx(InternalProvider, { | ||
actions: wrappedActions, | ||
children: props.children, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use client'; | ||
import { createContext, useContext } from 'react'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
|
||
const ActionContext = createContext(null); | ||
|
||
export function useActions() { | ||
return useContext(ActionContext); | ||
} | ||
|
||
export function InternalProvider(props) { | ||
return jsx('div', { | ||
'data-testid': 'ai-internal-provider', | ||
children: jsx(ActionContext.Provider, { | ||
value: props.actions, | ||
children: props.children, | ||
}), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
e2e/fixtures/rsc-basic/src/components/ServerAction/Client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use client'; | ||
|
||
import { useActions } from 'ai/rsc'; | ||
import { useEffect } from 'react'; | ||
|
||
export const ClientActionsConsumer = () => { | ||
const actions = useActions(); | ||
useEffect(() => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
globalThis.actions = actions; | ||
}, [actions]); | ||
return <div>globalThis.actions: {JSON.stringify(Object.keys(actions))}</div>; | ||
}; |
13 changes: 13 additions & 0 deletions
13
e2e/fixtures/rsc-basic/src/components/ServerAction/Server.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { ReactNode } from 'react'; | ||
import { createAI } from 'ai/rsc'; | ||
|
||
const AI = createAI({ | ||
foo: async () => { | ||
'use server'; | ||
return 0; | ||
}, | ||
}); | ||
|
||
export function ServerProvider({ children }: { children: ReactNode }) { | ||
return <AI>{children}</AI>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ export async function renderRsc( | |
), | ||
]); | ||
|
||
const bundlerConfig = new Proxy( | ||
const clientBundlerConfig = new Proxy( | ||
{}, | ||
{ | ||
get(_target, encodedId: string) { | ||
|
@@ -104,6 +104,22 @@ export async function renderRsc( | |
}, | ||
); | ||
|
||
const serverBundlerConfig = new Proxy( | ||
{}, | ||
{ | ||
get(_target, encodedId: string) { | ||
const [fileId, name] = encodedId.split('#') as [string, string]; | ||
const id = filePathToFileURL(fileId); | ||
if (fileId.startsWith('@id/assets/')) { | ||
const id = '.' + fileId.slice('@id'.length); | ||
return { id, chunks: [id], name, async: true }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will be and because rsdw.js is in dist/rsdw.js, it import() will work |
||
} else { | ||
return { id, chunks: [id], name, async: true }; | ||
} | ||
}, | ||
}, | ||
); | ||
|
||
const renderWithContext = async ( | ||
context: Record<string, unknown> | undefined, | ||
input: string, | ||
|
@@ -128,7 +144,7 @@ export async function renderRsc( | |
if (Object.keys(elements).some((key) => key.startsWith('_'))) { | ||
throw new Error('"_" prefix is reserved'); | ||
} | ||
return renderToReadableStream(elements, bundlerConfig, { | ||
return renderToReadableStream(elements, clientBundlerConfig, { | ||
onError, | ||
}); | ||
}); | ||
|
@@ -168,7 +184,7 @@ export async function renderRsc( | |
} | ||
return renderToReadableStream( | ||
{ ...elements, _value: actionValue }, | ||
bundlerConfig, | ||
clientBundlerConfig, | ||
{ | ||
onError, | ||
}, | ||
|
@@ -189,9 +205,9 @@ export async function renderRsc( | |
) { | ||
// XXX This doesn't support streaming unlike busboy | ||
const formData = parseFormData(bodyStr, contentType); | ||
args = await decodeReply(formData); | ||
args = await decodeReply(formData, serverBundlerConfig); | ||
} else if (bodyStr) { | ||
args = await decodeReply(bodyStr); | ||
args = await decodeReply(bodyStr, serverBundlerConfig); | ||
} | ||
const [fileId, name] = rsfId.split('#') as [string, string]; | ||
let mod: any; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this won't work because node condition is not including
react-server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's why you need a vite server to load the module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and import() doesn't support .ts(x) file in dev side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but it should work on PRD, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, but ID is not correct; it is now like
/path/to/file
which is presented as HTTP resource