-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate hydration scripts into just one (#3571)
* Remove redundant hydration scripts * Prebuild the island JS * Fix build * Updates to tests * Update more references * Custom element test now has two classic scripts * Account for non-default exports * Restructure hydration directives * Move nested logic into the island component * Remove try/catch
- Loading branch information
Showing
37 changed files
with
533 additions
and
288 deletions.
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,7 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import react from '@astrojs/react'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [react()], | ||
}); |
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 @@ | ||
{ | ||
"name": "@e2e/pass-js", | ||
"version": "0.0.0", | ||
"private": true, | ||
"devDependencies": { | ||
"@astrojs/react": "workspace:*", | ||
"astro": "workspace:*" | ||
}, | ||
"dependencies": { | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0" | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/astro/e2e/fixtures/pass-js/src/components/React.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,29 @@ | ||
import type { BigNestedObject } from '../types'; | ||
import { useState } from 'react'; | ||
|
||
interface Props { | ||
obj: BigNestedObject; | ||
num: bigint; | ||
} | ||
|
||
const isNode = typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]'; | ||
|
||
/** a counter written in React */ | ||
export default function Component({ obj, num, arr }: Props) { | ||
// We are testing hydration, so don't return anything in the server. | ||
if(isNode) { | ||
return <div></div> | ||
} | ||
|
||
return ( | ||
<div> | ||
<span id="nested-date">{obj.nested.date.toUTCString()}</span> | ||
<span id="regexp-type">{Object.prototype.toString.call(obj.more.another.exp)}</span> | ||
<span id="regexp-value">{obj.more.another.exp.source}</span> | ||
<span id="bigint-type">{Object.prototype.toString.call(num)}</span> | ||
<span id="bigint-value">{num.toString()}</span> | ||
<span id="arr-type">{Object.prototype.toString.call(arr)}</span> | ||
<span id="arr-value">{arr.join(',')}</span> | ||
</div> | ||
); | ||
} |
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,28 @@ | ||
--- | ||
import Component from '../components/React'; | ||
import { BigNestedObject } from '../types'; | ||
const obj: BigNestedObject = { | ||
nested: { | ||
date: new Date('Thu, 09 Jun 2022 14:18:27 GMT') | ||
}, | ||
more: { | ||
another: { | ||
exp: /ok/ | ||
} | ||
} | ||
}; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<link rel="icon" type="image/x-icon" href="/favicon.ico" /> | ||
</head> | ||
<body> | ||
<main> | ||
<Component client:load obj={obj} num={11n} arr={[0, "foo"]} /> | ||
</main> | ||
</body> | ||
</html> |
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,11 @@ | ||
|
||
export interface BigNestedObject { | ||
nested: { | ||
date: Date; | ||
}; | ||
more: { | ||
another: { | ||
exp: RegExp; | ||
} | ||
} | ||
} |
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,61 @@ | ||
import { test as base, expect } from '@playwright/test'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
const test = base.extend({ | ||
astro: async ({}, use) => { | ||
const fixture = await loadFixture({ root: './fixtures/pass-js/' }); | ||
await use(fixture); | ||
}, | ||
}); | ||
|
||
let devServer; | ||
|
||
test.beforeEach(async ({ astro }) => { | ||
devServer = await astro.startDevServer(); | ||
}); | ||
|
||
test.afterEach(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
test.describe('Passing JS into client components', () => { | ||
test('Complex nested objects', async ({ astro, page }) => { | ||
await page.goto('/'); | ||
|
||
const nestedDate = await page.locator('#nested-date'); | ||
await expect(nestedDate, 'component is visible').toBeVisible(); | ||
await expect(nestedDate).toHaveText('Thu, 09 Jun 2022 14:18:27 GMT'); | ||
|
||
const regeExpType = await page.locator('#regexp-type'); | ||
await expect(regeExpType, 'is visible').toBeVisible(); | ||
await expect(regeExpType).toHaveText('[object RegExp]'); | ||
|
||
const regExpValue = await page.locator('#regexp-value'); | ||
await expect(regExpValue, 'is visible').toBeVisible(); | ||
await expect(regExpValue).toHaveText('ok'); | ||
}); | ||
|
||
test('BigInts', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
const bigIntType = await page.locator('#bigint-type'); | ||
await expect(bigIntType, 'is visible').toBeVisible(); | ||
await expect(bigIntType).toHaveText('[object BigInt]'); | ||
|
||
const bigIntValue = await page.locator('#bigint-value'); | ||
await expect(bigIntValue, 'is visible').toBeVisible(); | ||
await expect(bigIntValue).toHaveText('11'); | ||
}); | ||
|
||
test('Arrays that look like the serialization format', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
const arrType = await page.locator('#arr-type'); | ||
await expect(arrType, 'is visible').toBeVisible(); | ||
await expect(arrType).toHaveText('[object Array]'); | ||
|
||
const arrValue = await page.locator('#arr-value'); | ||
await expect(arrValue, 'is visible').toBeVisible(); | ||
await expect(arrValue).toHaveText('0,foo'); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -221,6 +221,7 @@ ${extra}` | |
}, | ||
resolve, | ||
_metadata: { | ||
needsHydrationStyles: false, | ||
renderers, | ||
pathname, | ||
}, | ||
|
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
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
Oops, something went wrong.