Skip to content

Commit

Permalink
Merge branch 'main' into juanm04/vercel-build-output-api
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanM04 committed May 11, 2022
2 parents 39f2663 + 1a5335e commit 7a20b3b
Show file tree
Hide file tree
Showing 44 changed files with 454 additions and 105 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-keys-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

create redirects file for netlify edge adapter
5 changes: 5 additions & 0 deletions .changeset/happy-wasps-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes HMR of hoisted script tags
5 changes: 5 additions & 0 deletions .changeset/healthy-oranges-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue preventing custom 404 pages in dev
5 changes: 5 additions & 0 deletions .changeset/heavy-adults-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

fixes injectscript in ssr mode
5 changes: 5 additions & 0 deletions .changeset/new-carrots-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fix an `import from '../core/build/types';` error
5 changes: 5 additions & 0 deletions .changeset/olive-grapes-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix for swallowed SolidJS errors
5 changes: 5 additions & 0 deletions .changeset/strong-students-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Update "next steps" with more informative text on each CLI command. Oh, and gradients. A lot more gradients.
6 changes: 6 additions & 0 deletions .changeset/violet-bees-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/svelte': patch
'@astrojs/vue': patch
---

Fix a vite peer dependency bug
5 changes: 1 addition & 4 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ example:
'🚨 action':
- .github/workflows/**

test:
- packages/**/*.test.js

core:
- packages/astro/**

Expand All @@ -18,7 +15,7 @@ create-astro:
markdown:
- packages/markdown/**

renderer:
integration:
- packages/integrations/**

framework-lit:
Expand Down
11 changes: 7 additions & 4 deletions examples/docs/src/components/Header/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const lang = currentPage && getLanguageFromURL(currentPage);
<SidebarToggle client:idle />
</div>
<div class="logo flex">
<AstroLogo size={40} />
<a href="/">
<AstroLogo size={40} />
<h1>{CONFIG.SITE.title ?? "Documentation"}</h1>
</a>
</div>
Expand Down Expand Up @@ -48,6 +48,7 @@ const lang = currentPage && getLanguageFromURL(currentPage);
}

.logo {
flex: 1;
display: flex;
overflow: hidden;
width: 30px;
Expand All @@ -61,6 +62,7 @@ const lang = currentPage && getLanguageFromURL(currentPage);
}

.logo a {
display: flex;
padding: 0.5em 0.25em;
margin: -0.5em -0.25em;
text-decoration: none;
Expand All @@ -78,6 +80,7 @@ const lang = currentPage && getLanguageFromURL(currentPage);
}

.logo h1 {
display: none;
font: inherit;
color: inherit;
margin: 0;
Expand All @@ -103,12 +106,12 @@ const lang = currentPage && getLanguageFromURL(currentPage);
margin: 0;
z-index: 0;
}
.logo h1 {
display: initial;
}
.menu-toggle {
display: none;
}
.logo {
width: auto;
}
}

/** Style Algolia */
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const SITE = {
title: 'Your Documentation Website',
title: 'Documentation',
description: 'Your website description.',
defaultLanguage: 'en_US',
};
Expand Down
5 changes: 3 additions & 2 deletions examples/integrations-playground/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { defineConfig } from 'astro/config';

import lit from '@astrojs/lit';
import react from '@astrojs/react';
import tailwind from '@astrojs/tailwind';
import turbolinks from '@astrojs/turbolinks';
import sitemap from '@astrojs/sitemap';
import partytown from '@astrojs/partytown';
import solid from '@astrojs/solid-js';

// https://astro.build/config
export default defineConfig({
integrations: [lit(), react(), tailwind(), turbolinks(), partytown(), sitemap()],
integrations: [lit(), react(), tailwind(), turbolinks(), partytown(), sitemap(), solid()],
});
5 changes: 3 additions & 2 deletions examples/integrations-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
"@astrojs/partytown": "^0.1.2",
"@astrojs/react": "^0.1.1",
"@astrojs/sitemap": "^0.1.0",
"@astrojs/solid-js": "0.1.2",
"@astrojs/tailwind": "^0.2.1",
"@astrojs/turbolinks": "^0.1.2",
"astro": "^1.0.0-beta.27"
"astro": "^1.0.0-beta.27",
"solid-js": "^1.3.6"
},
"dependencies": {
"@webcomponents/template-shadowroot": "^0.1.0",
"lit": "^2.2.2",
"preact": "^10.7.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"solid-js": "^1.3.16",
"svelte": "^3.47.0",
"vue": "^3.2.33"
}
Expand Down
3 changes: 3 additions & 0 deletions examples/integrations-playground/src/components/Link.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* jsxImportSource: react */
import React from 'react';

export default function Link({ to, text }) {
return <a href={to}>{text}</a>;
}
18 changes: 18 additions & 0 deletions examples/integrations-playground/src/components/SolidCounter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createSignal } from 'solid-js';

export default function Counter(props) {
const [count, setCount] = createSignal(0);
const add = () => setCount(count() + 1);
const subtract = () => setCount(count() - 1);

return (
<>
<div class="counter">
<button onClick={subtract}>-</button>
<pre>{count()}</pre>
<button onClick={add}>+</button>
</div>
<div class="counter-message">{props.children}</div>
</>
);
}
12 changes: 6 additions & 6 deletions examples/integrations-playground/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
import Lorem from '../components/Lorem.astro';
import Link from '../components/Link.jsx';
import SolidCounter from '../components/SolidCounter.jsx';
import '../components/Test.js';
import '../components/Counter.js';
import '../components/Counter.js';
---

<!DOCTYPE html>
Expand All @@ -14,20 +15,19 @@ import '../components/Counter.js';
<body>
<h1 class="px-4 py-4">Test app</h1>
<h2 class="partytown-status">
<strong>Party Mode!</strong>
<strong>Party Mode!</strong>
Colors changing = partytown is enabled
</h2>
<my-counter client:load></my-counter>
<SolidCounter client:load></SolidCounter>
<Link to="/foo" text="Go to Page 2" />
<Lorem />
<calc-add num={33}></calc-add>


<script type="text/partytown">
// Remove `type="text/partytown"` to see this block the page
// and cause the page to become unresponsive
console.log('start partytown blocking script')
const now = Date.now()
const now = Date.now()
let count = 1;
while (Date.now() - now < 10000) {
if (Date.now() - now > count * 1000) {
Expand All @@ -46,7 +46,7 @@ import '../components/Counter.js';
</script>
<style>
h1, h2 {
color: blue;
color: blue;
}
</style>
</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
<body>
<h1>Astro</h1>
</body>
</html>
</html>
8 changes: 4 additions & 4 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export interface AstroUserConfig {
* {
* markdown: {
* // Example: The default set of remark plugins used by Astro
* remarkPlugins: ['remark-code-titles', ['rehype-autolink-headings', { behavior: 'prepend' }]],
* remarkPlugins: ['remark-gfm', 'remark-smartypants'],
* },
* };
* ```
Expand All @@ -582,7 +582,7 @@ export interface AstroUserConfig {
* {
* markdown: {
* // Example: The default set of rehype plugins used by Astro
* rehypePlugins: ['rehype-slug', ['rehype-toc', { headings: ['h2', 'h3'] }], [addClasses, { 'h1,h2,h3': 'title' }]],
* rehypePlugins: [],
* },
* };
* ```
Expand Down Expand Up @@ -770,8 +770,8 @@ export type GetHydrateCallback = () => Promise<
* getStaticPaths() options
* Docs: https://docs.astro.build/reference/api-reference/#getstaticpaths
*/ export interface GetStaticPathsOptions {
paginate?: PaginateFunction;
rss?: (...args: any[]) => any;
paginate: PaginateFunction;
rss: (...args: any[]) => any;
}

export type GetStaticPathsItem = { params: Params; props?: Props };
Expand Down
16 changes: 15 additions & 1 deletion packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@ export class App {
const renderers = manifest.renderers;
const info = this.#routeDataToRouteInfo.get(routeData!)!;
const links = createLinkStylesheetElementSet(info.links, manifest.site);
const scripts = createModuleScriptElementWithSrcSet(info.scripts, manifest.site);

const filteredScripts = info.scripts.filter(
(script) => typeof script !== 'string' && script?.stage !== 'head-inline'
) as string[];
const scripts = createModuleScriptElementWithSrcSet(filteredScripts, manifest.site);

// Add all injected scripts to the page.
for (const script of info.scripts) {
if (typeof script !== 'string' && script.stage === 'head-inline') {
scripts.add({
props: {},
children: script.children,
});
}
}

const result = await render({
links,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface RouteInfo {
routeData: RouteData;
file: string;
links: string[];
scripts: string[];
scripts: Array<string | { children: string; stage: string }>;
}

export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type {
ComponentInstance,
SSRLoadedRenderer,
} from '../../@types/astro';
import type { ViteConfigWithSSR } from '../../create-vite';
import type { LogOptions } from '../../logger';
import type { RouteCache } from '../../render/route-cache.js';
import type { LogOptions } from '../logger/core';
import type { RouteCache } from '../render/route-cache';
import type { ViteConfigWithSSR } from '../create-vite';

export type ComponentPath = string;
export type ViteID = string;
Expand Down
7 changes: 6 additions & 1 deletion packages/astro/src/core/build/vite-plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ function buildManifest(
routes.push({
file: '',
links: Array.from(pageData.css),
scripts,
scripts: [
...scripts,
...astroConfig._ctx.scripts
.filter((script) => script.stage === 'head-inline')
.map(({ stage, content }) => ({ stage, children: content })),
],
routeData: serializeRouteData(pageData.route),
});
}
Expand Down
15 changes: 12 additions & 3 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,22 @@ Did you mean to add ${formatList(probableRendererNames.map((r) => '`' + r + '`')
// Call the renderers `check` hook to see if any claim this component.
let renderer: SSRLoadedRenderer | undefined;
if (metadata.hydrate !== 'only') {
let error;
for (const r of renderers) {
if (await r.ssr.check(Component, props, children)) {
renderer = r;
break;
try {
if (await r.ssr.check(Component, props, children)) {
renderer = r;
break;
}
} catch (e) {
error ??= e;
}
}

if (error) {
throw error;
}

if (!renderer && typeof HTMLElement === 'function' && componentIsHTMLElement(Component)) {
const output = renderHTMLElement(result, Component as typeof HTMLElement, _props, slots);

Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/vite-plugin-astro-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type http from 'http';
import type { AstroConfig, ManifestData } from '../@types/astro';
import type { RenderResponse, SSROptions } from '../core/render/dev/index';
import { debug, info, warn, error, LogOptions } from '../core/logger/core.js';
import { appendForwardSlash } from '../core/path.js';
import { getParamsAndProps, GetParamsAndPropsError } from '../core/render/core.js';
import { createRouteManifest, matchRoute } from '../core/routing/index.js';
import stripAnsi from 'strip-ansi';
Expand Down Expand Up @@ -166,7 +167,7 @@ async function handle500Response(

function getCustom404Route(config: AstroConfig, manifest: ManifestData) {
const relPages = resolvePages(config).href.replace(config.root.href, '');
return manifest.routes.find((r) => r.component === relPages + '404.astro');
return manifest.routes.find((r) => r.component === appendForwardSlash(relPages) + '404.astro');
}

function log404(logging: LogOptions, pathname: string) {
Expand Down
10 changes: 10 additions & 0 deletions packages/astro/src/vite-plugin-astro/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg
filtered.add(mod);
files.add(mod.file);
}

for (const imp of mod.importers) {
if (imp.file && isCached(config, imp.file)) {
filtered.add(imp);
Expand All @@ -85,6 +86,15 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg
// Bugfix: sometimes style URLs get normalized and end with `lang.css=`
// These will cause full reloads, so filter them out here
const mods = ctx.modules.filter((m) => !m.url.endsWith('='));

// Add hoisted scripts so these get invalidated
for (const mod of mods) {
for (const imp of mod.importedModules) {
if (imp.id?.includes('?astro&type=script')) {
mods.push(imp);
}
}
}
const isSelfAccepting = mods.every((m) => m.isSelfAccepting || m.url.endsWith('.svelte'));

const file = ctx.file.replace(config.root.pathname, '/');
Expand Down
Loading

0 comments on commit 7a20b3b

Please sign in to comment.