-
-
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.
Support alias use with hydration scripts (#3376)
* Support alias use with hydration scripts * Adds a changeset * Updated lockfile
- Loading branch information
Showing
10 changed files
with
114 additions
and
15 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,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Allow using aliases for hydrated scripts |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { isWindows, loadFixture } from './test-utils.js'; | ||
|
||
describe('Aliases', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/alias/', | ||
}); | ||
}); | ||
|
||
if (isWindows) return; | ||
|
||
describe('dev', () => { | ||
let devServer; | ||
|
||
before(async () => { | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
it.only('can load client components', async () => { | ||
const html = await fixture.fetch('/').then((res) => res.text()); | ||
const $ = cheerio.load(html); | ||
|
||
// Should render aliased element | ||
expect($('#client').text()).to.equal('test'); | ||
|
||
const scripts = $('script').toArray(); | ||
expect(scripts.length).to.be.greaterThan(0); | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import svelte from '@astrojs/svelte'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [svelte()], | ||
vite: { | ||
resolve: { | ||
alias: [ | ||
{ find:/^component:(.*)$/, replacement: '/src/components/$1' } | ||
] | ||
} | ||
} | ||
}); |
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,9 @@ | ||
{ | ||
"name": "@test/aliases", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/svelte": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/astro/test/fixtures/alias/src/components/Client.svelte
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,2 @@ | ||
<script></script> | ||
<div id="client">test</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,25 @@ | ||
--- | ||
import Client from 'component:Client.svelte' | ||
--- | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Svelte Client</title> | ||
<style> | ||
html, | ||
body { | ||
font-family: system-ui; | ||
margin: 0; | ||
} | ||
body { | ||
padding: 2rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<Client client:load /> | ||
</main> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.