Skip to content

Commit

Permalink
Fix bundling of client entry chunks (#2932)
Browse files Browse the repository at this point in the history
* Fix promise fallback data

* fix
  • Loading branch information
huozhi authored Apr 6, 2024
1 parent 1a40acc commit f59b7c8
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 42 deletions.
17 changes: 17 additions & 0 deletions e2e/site/app/suspense-fallback/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SWRConfig } from 'swr'

function createPromiseData(data: any, timeout: number) {
return new Promise(resolve => {
setTimeout(() => {
resolve(data)
}, timeout)
})
}

export default function Layout({ children }: { children: React.ReactNode }) {
const fallback = {
'/api/promise': createPromiseData({ value: 'async promise' }, 2000)
}

return <SWRConfig value={{ fallback }}>{children}</SWRConfig>
}
9 changes: 9 additions & 0 deletions e2e/site/app/suspense-fallback/promise/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import useSWR from 'swr'

export default function Page() {
const { data, isLoading } = useSWR('/api/promise')

return <div>{isLoading ? 'loading...' : data?.value}</div>
}
6 changes: 1 addition & 5 deletions e2e/site/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverActions: true,
},
}
const nextConfig = {}

module.exports = nextConfig
2 changes: 1 addition & 1 deletion e2e/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@types/node": "^20.2.5",
"@types/react": "^18.2.8",
"@types/react-dom": "18.2.4",
"next": "^13.4.4",
"next": "^14.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "5.1.3",
Expand Down
11 changes: 11 additions & 0 deletions e2e/test/suspense-fallback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable testing-library/prefer-screen-queries */
import { test, expect } from '@playwright/test'

test.describe('suspense fallback', () => {
test('should wait for promise fallback value to be resolved', async ({
page
}) => {
await page.goto('./suspense-fallback/promise', { waitUntil: 'commit' })
await expect(page.getByText('async promise')).toBeVisible()
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"lint-staged": "13.2.2",
"next": "14.1.0",
"next": "14.1.4",
"prettier": "2.8.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
68 changes: 34 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/index/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use client'

// TODO: fix SWRConfig re-use issue with bundler
import { SWRConfig as S } from '../_internal'
export const SWRConfig = S
2 changes: 1 addition & 1 deletion src/index/index.react-server.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { unstable_serialize } from '../core/serialize'
export { SWRConfig } from '../_internal'
export { SWRConfig } from './config'

0 comments on commit f59b7c8

Please sign in to comment.