Skip to content

Commit

Permalink
fix: support runtime value when using multiple declarations per export (
Browse files Browse the repository at this point in the history
#44732)

Fixes a bug where the export syntax with multiple declarations didn't
work. I.e. this now works:

```
export const foo = 'bar', runtime = 'edge'
```


[x-slack-ref](https://vercel.slack.com/archives/C03LF48T3B7/p1673152323630709)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
feedthejim authored Jan 9, 2023
1 parent 33d7870 commit 2d03237
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ function checkExports(swcAST: any): {
node.type === 'ExportDeclaration' &&
node.declaration?.type === 'VariableDeclaration'
) {
const id = node.declaration?.declarations[0]?.id.value
if (id === 'runtime') {
runtime = node.declaration?.declarations[0]?.init.value
for (const declaration of node.declaration?.declarations) {
if (declaration.id.value === 'runtime') {
runtime = declaration.init.value
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/e2e/switchable-runtime/app/app-valid-runtime/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Time from '../../utils/time'
import Runtime from '../../utils/runtime'

export default function Page() {
return (
<div>
This is a SSR RSC page.
<br />
<Runtime />
<br />
<Time />
</div>
)
}

export const foo = 'bar',
runtime = 'edge'
7 changes: 7 additions & 0 deletions test/e2e/switchable-runtime/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,13 @@ describe('Switchable runtime', () => {
})
})

it('should build /app-valid-runtime as a dynamic page with the edge runtime', async () => {
await testRoute(context.appPort, '/app-valid-runtime', {
isStatic: false,
isEdge: true,
})
})

// FIXME: rsc hydration
it.skip('should build /node-rsc-ssr as a dynamic page with the nodejs runtime', async () => {
await testRoute(context.appPort, '/node-rsc-ssr', {
Expand Down

0 comments on commit 2d03237

Please sign in to comment.