Skip to content

Commit 1dc756e

Browse files
authored
Fixes using React.lazy and Suspense (#3160)
* Revert "Revert "Fixes using React.lazy and Suspense"" This reverts commit 62e93ec. * Adds a changeset * Fix ts errors * Remove netlify metadata folder
1 parent 62e93ec commit 1dc756e

7 files changed

Lines changed: 26 additions & 2 deletions

File tree

packages/integrations/netlify/src/integration-edge-functions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
8686
},
8787
'astro:build:setup': ({ vite, target }) => {
8888
if (target === 'server') {
89+
vite.resolve = vite.resolve || {};
90+
vite.resolve.alias = vite.resolve.alias || {};
91+
const alias = vite.resolve.alias as Record<string, string>;
92+
alias['react-dom/server'] = 'react-dom/server.browser'
8993
vite.ssr = {
9094
noExternal: true,
9195
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// @ts-nocheck
22
export { fromFileUrl } from 'https://deno.land/std@0.110.0/path/mod.ts';
33
export { assertEquals, assert } from 'https://deno.land/std@0.132.0/testing/asserts.ts';
4+
export * from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts';
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
// @ts-ignore
22
import { runBuild } from './test-utils.ts';
33
// @ts-ignore
4-
import { assertEquals, assert } from './deps.ts';
4+
import { assertEquals, assert, DOMParser } from './deps.ts';
55

66
// @ts-ignore
77
Deno.test({
88
name: 'Edge Basics',
99
async fn() {
1010
let close = await runBuild('./fixtures/edge-basic/');
1111
const { default: handler } = await import(
12-
'./fixtures/edge-basic/dist/edge-functions/entry.mjs'
12+
'./fixtures/edge-basic/dist/edge-functions/entry.js'
1313
);
1414
const response = await handler(new Request('http://example.com/'));
1515
assertEquals(response.status, 200);
1616
const html = await response.text();
1717
assert(html, 'got some html');
18+
19+
const doc = new DOMParser().parseFromString(html, `text/html`)!;
20+
const div = doc.querySelector('#react');
21+
assert(div, 'div exists');
22+
1823
await close();
1924
},
2025
});

packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { defineConfig } from 'astro/config';
22
import { netlifyEdgeFunctions } from '@astrojs/netlify';
3+
import react from "@astrojs/react";
34

45
export default defineConfig({
56
adapter: netlifyEdgeFunctions({
67
dist: new URL('./dist/', import.meta.url),
78
}),
9+
integrations: [react()],
810
experimental: {
911
ssr: true
1012
}

packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"astro": "workspace:*",
7+
"@astrojs/react": "workspace:*",
78
"@astrojs/netlify": "workspace:*"
89
}
910
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
export default function() {
4+
return (
5+
<div id="react">testing</div>
6+
)
7+
}

packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/src/pages/index.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
import ReactComponent from '../components/React.jsx';
3+
---
14
<html>
25
<head><title>Testing</title></head>
36
<body>
@@ -6,5 +9,6 @@
69
<ul>
710
<li><a href="/two/">Two</a></li>
811
</ul>
12+
<ReactComponent />
913
</body>
1014
</html>

0 commit comments

Comments
 (0)