Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored and astrobot-houston committed Jun 13, 2024
1 parent 4385bf7 commit a6df7e8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/container-with-vitest/test/ReactWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ReactWrapper from '../src/components/ReactWrapper.astro';

const renderers = await loadRenderers([getContainerRenderer()]);
const container = await AstroContainer.create({
renderers
renderers,
});

test('ReactWrapper with react renderer', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2977,7 +2977,7 @@ export interface AstroRenderer {
jsxTransformOptions?: JSXTransformFn;
}

export type SSRLoadedRendererValue = {
export type SSRLoadedRendererValue = {
check: AsyncRendererComponentFn<boolean>;
renderToStaticMarkup: AsyncRendererComponentFn<{
html: string;
Expand All @@ -2996,7 +2996,7 @@ export type SSRLoadedRendererValue = {
* page-level data structure.
*/
renderHydrationScript?: () => string;
}
};

export interface SSRLoadedRenderer extends Pick<AstroRenderer, 'name' | 'clientEntrypoint'> {
ssr: SSRLoadedRendererValue;
Expand Down
31 changes: 17 additions & 14 deletions packages/astro/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import type {
Props,
RouteData,
RouteType,
SSRLoadedRenderer, SSRLoadedRendererValue,
SSRLoadedRenderer,
SSRLoadedRendererValue,
SSRManifest,
SSRResult,
} from '../@types/astro.js';
Expand Down Expand Up @@ -270,34 +271,36 @@ export class experimental_AstroContainer {

/**
* Use this function to manually add a renderer to the container.
*
* This function is preferred when you require to use the container with a renderer in environments such as on-demand pages.
*
*
* This function is preferred when you require to use the container with a renderer in environments such as on-demand pages.
*
* ## Example
*
*
* ```js
* import reactRenderer from "@astrojs/react/server.js";
* import vueRenderer from "@astrojs/vue/server.js";
* import { experimental_AstroContainer as AstroContainer } from "astro/container"
*
*
* const container = await AstroContainer.create();
* container.addServerRenderer("@astrojs/react", reactRenderer);
* container.addServerRenderer("@astrojs/vue", vueRenderer);
* ```
*
* @param name The name of the renderer. The name **isn't** arbitrary, and it should match the name of the package.
* @param renderer The server renderer exported by integration.
*
* @param name The name of the renderer. The name **isn't** arbitrary, and it should match the name of the package.
* @param renderer The server renderer exported by integration.
*/
public addServerRenderer(name: string, renderer: SSRLoadedRendererValue) {
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" +
"Usually, the renderer is exported by a /server.js entrypoint e.g. `import renderer from '@astrojs/react/server.js'`")
throw new Error(
"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({
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.
Expand Down
25 changes: 12 additions & 13 deletions packages/astro/test/container.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 {
Fragment,
Expand All @@ -12,8 +12,8 @@ import {
renderSlot,
renderTemplate,
} 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) => {
return render`<html>
Expand Down Expand Up @@ -234,24 +234,23 @@ describe('Container', () => {
});

describe('Container with renderers', () => {
let fixture
let fixture;
let app;
before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/container-react/', import.meta.url),
output: "server",
adapter: testAdapter()
output: 'server',
adapter: testAdapter(),
});
await fixture.build();
app = await fixture.loadTestAdapterApp();
});

it("the endpoint should return the HTML of the React component", async () => {
const request = new Request("https://example.com/api");
const response = await app.render(request)
const html = await response.text()
it('the endpoint should return the HTML of the React component', async () => {
const request = new Request('https://example.com/api');
const response = await app.render(request);
const html = await response.text();

assert.match(html, /I am a react button/)
})
assert.match(html, /I am a react button/);
});
});

1 change: 0 additions & 1 deletion packages/integrations/react/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,3 @@ export default {
renderToStaticMarkup,
supportsAstroStaticSlot: true,
};

6 changes: 3 additions & 3 deletions packages/integrations/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 ReactVersionConfig,
type SupportedReactVersion,
getReactMajorVersion,
isUnsupportedVersion,
versionsConfig,
type ReactVersionConfig,
type SupportedReactVersion,
} from './version.js';

export type ReactIntegrationOptions = Pick<
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"include": ["src"],
"compilerOptions": {
"outDir": "./dist"
},
}
}

0 comments on commit a6df7e8

Please sign in to comment.