mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
4385bf7a4d
commit
a6df7e877f
7 changed files with 36 additions and 35 deletions
|
@ -6,7 +6,7 @@ import ReactWrapper from '../src/components/ReactWrapper.astro';
|
||||||
|
|
||||||
const renderers = await loadRenderers([getContainerRenderer()]);
|
const renderers = await loadRenderers([getContainerRenderer()]);
|
||||||
const container = await AstroContainer.create({
|
const container = await AstroContainer.create({
|
||||||
renderers
|
renderers,
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ReactWrapper with react renderer', async () => {
|
test('ReactWrapper with react renderer', async () => {
|
||||||
|
|
|
@ -2996,7 +2996,7 @@ export type SSRLoadedRendererValue = {
|
||||||
* page-level data structure.
|
* page-level data structure.
|
||||||
*/
|
*/
|
||||||
renderHydrationScript?: () => string;
|
renderHydrationScript?: () => string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface SSRLoadedRenderer extends Pick<AstroRenderer, 'name' | 'clientEntrypoint'> {
|
export interface SSRLoadedRenderer extends Pick<AstroRenderer, 'name' | 'clientEntrypoint'> {
|
||||||
ssr: SSRLoadedRendererValue;
|
ssr: SSRLoadedRendererValue;
|
||||||
|
|
|
@ -8,7 +8,8 @@ import type {
|
||||||
Props,
|
Props,
|
||||||
RouteData,
|
RouteData,
|
||||||
RouteType,
|
RouteType,
|
||||||
SSRLoadedRenderer, SSRLoadedRendererValue,
|
SSRLoadedRenderer,
|
||||||
|
SSRLoadedRendererValue,
|
||||||
SSRManifest,
|
SSRManifest,
|
||||||
SSRResult,
|
SSRResult,
|
||||||
} from '../@types/astro.js';
|
} from '../@types/astro.js';
|
||||||
|
@ -290,14 +291,16 @@ export class experimental_AstroContainer {
|
||||||
*/
|
*/
|
||||||
public addServerRenderer(name: string, renderer: SSRLoadedRendererValue) {
|
public addServerRenderer(name: string, renderer: SSRLoadedRendererValue) {
|
||||||
if (!renderer.check || !renderer.renderToStaticMarkup) {
|
if (!renderer.check || !renderer.renderToStaticMarkup) {
|
||||||
throw new Error("The renderer you passed isn't valid. A renderer is usually an object that exposes the `check` and `renderToStaticMarkup` functions.\n" +
|
throw new Error(
|
||||||
"Usually, the renderer is exported by a /server.js entrypoint e.g. `import renderer from '@astrojs/react/server.js'`")
|
"The renderer you passed isn't valid. A renderer is usually an object that exposes the `check` and `renderToStaticMarkup` functions.\n" +
|
||||||
|
"Usually, the renderer is exported by a /server.js entrypoint e.g. `import renderer from '@astrojs/react/server.js'`"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#pipeline.manifest.renderers.push({
|
this.#pipeline.manifest.renderers.push({
|
||||||
name,
|
name,
|
||||||
ssr: renderer
|
ssr: renderer,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
|
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { describe, it, before } from 'node:test';
|
import { before, describe, it } from 'node:test';
|
||||||
import { experimental_AstroContainer } from '../dist/container/index.js';
|
import { experimental_AstroContainer } from '../dist/container/index.js';
|
||||||
import {
|
import {
|
||||||
Fragment,
|
Fragment,
|
||||||
|
@ -12,8 +12,8 @@ import {
|
||||||
renderSlot,
|
renderSlot,
|
||||||
renderTemplate,
|
renderTemplate,
|
||||||
} from '../dist/runtime/server/index.js';
|
} from '../dist/runtime/server/index.js';
|
||||||
import {loadFixture} from "./test-utils.js";
|
import testAdapter from './test-adapter.js';
|
||||||
import testAdapter from "./test-adapter.js";
|
import { loadFixture } from './test-utils.js';
|
||||||
|
|
||||||
const BaseLayout = createComponent((result, _props, slots) => {
|
const BaseLayout = createComponent((result, _props, slots) => {
|
||||||
return render`<html>
|
return render`<html>
|
||||||
|
@ -234,24 +234,23 @@ describe('Container', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Container with renderers', () => {
|
describe('Container with renderers', () => {
|
||||||
let fixture
|
let fixture;
|
||||||
let app;
|
let app;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: new URL('./fixtures/container-react/', import.meta.url),
|
root: new URL('./fixtures/container-react/', import.meta.url),
|
||||||
output: "server",
|
output: 'server',
|
||||||
adapter: testAdapter()
|
adapter: testAdapter(),
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
app = await fixture.loadTestAdapterApp();
|
app = await fixture.loadTestAdapterApp();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("the endpoint should return the HTML of the React component", async () => {
|
it('the endpoint should return the HTML of the React component', async () => {
|
||||||
const request = new Request("https://example.com/api");
|
const request = new Request('https://example.com/api');
|
||||||
const response = await app.render(request)
|
const response = await app.render(request);
|
||||||
const html = await response.text()
|
const html = await response.text();
|
||||||
|
|
||||||
assert.match(html, /I am a react button/)
|
assert.match(html, /I am a react button/);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -230,4 +230,3 @@ export default {
|
||||||
renderToStaticMarkup,
|
renderToStaticMarkup,
|
||||||
supportsAstroStaticSlot: true,
|
supportsAstroStaticSlot: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import react, { type Options as ViteReactPluginOptions } from '@vitejs/plugin-react';
|
import react, { type Options as ViteReactPluginOptions } from '@vitejs/plugin-react';
|
||||||
import type {AstroIntegration, ContainerRenderer} from 'astro';
|
import type { AstroIntegration, ContainerRenderer } from 'astro';
|
||||||
import type * as vite from 'vite';
|
import type * as vite from 'vite';
|
||||||
import {
|
import {
|
||||||
|
type ReactVersionConfig,
|
||||||
|
type SupportedReactVersion,
|
||||||
getReactMajorVersion,
|
getReactMajorVersion,
|
||||||
isUnsupportedVersion,
|
isUnsupportedVersion,
|
||||||
versionsConfig,
|
versionsConfig,
|
||||||
type ReactVersionConfig,
|
|
||||||
type SupportedReactVersion,
|
|
||||||
} from './version.js';
|
} from './version.js';
|
||||||
|
|
||||||
export type ReactIntegrationOptions = Pick<
|
export type ReactIntegrationOptions = Pick<
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./dist"
|
"outDir": "./dist"
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue