Skip to content

Commit

Permalink
fix: fix and test module runner dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 13, 2024
1 parent aeb54b6 commit 8d0708a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,13 @@ function patchRuntimePlugin(environment: RolldownEnvironment): rolldown.Plugin {
__rolldown_runtime.manifest = ${JSON.stringify(manifest, null, 2)};
`
}
if (chunk.name === 'hmr-update') {
// patch on hmr
if (environment.name === 'ssr') {
chunk.code += `
if (environment.name === 'ssr' && !chunk.isEntry) {
chunk.code += `
var __rolldown_runtime = __rolldown_module_runner_context.__rolldown_runtime;
`
}
}
if (chunk.name === 'hmr-update') {
// patch on hmr
chunk.code += `
__rolldown_runtime.patch(__rolldown_modules);
`
Expand Down
5 changes: 5 additions & 0 deletions playground/rolldown-dev-ssr/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ test.runIf(!isBuild)('hmr', async () => {
const res = await page.request.get(viteTestUrl)
expect(await res.text()).toContain('Count-x-y')
})

test('dynamic-import', async () => {
const res = await page.goto(viteTestUrl + '/dynamic-import')
expect(await res?.text()).toContain('[dynamic-import-ok]')
})
1 change: 1 addition & 0 deletions playground/rolldown-dev-ssr/src/dynamic-import.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default '[dynamic-import-ok]'
7 changes: 6 additions & 1 deletion playground/rolldown-dev-ssr/src/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import type { Connect } from 'vite'
import { App } from './app'
import { throwError } from './error'

const handler: Connect.SimpleHandleFunction = (req, res) => {
const handler: Connect.SimpleHandleFunction = async (req, res) => {
const url = new URL(req.url ?? '/', 'https://vite.dev')
console.log(`[SSR] ${req.method} ${url.pathname}`)
if (url.pathname === '/crash-ssr') {
throwError()
}
if (url.pathname === '/dynamic-import') {
const mod = await import('./dynamic-import')
res.end(mod.default)
return
}
const ssrHtml = ReactDOMServer.renderToString(<App />)
res.setHeader('content-type', 'text/html')
// TODO: transformIndexHtml?
Expand Down

0 comments on commit 8d0708a

Please sign in to comment.