0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-04-07 23:41:43 -05:00

fix(core): don't noop shared modules (#9828)

* fix(core): don't noop shared modules

* address feedback

* add test

* changeset

* check astro pages

* address feedback

---------

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Emanuele Stoppa 2024-01-26 17:17:32 +00:00 committed by GitHub
parent 996ab26255
commit 8a27b5eaa7
4 changed files with 56 additions and 2 deletions

View file

@ -0,0 +1,7 @@
import { shared } from './shared';
export const onRequest = (ctx, next) => {
ctx.locals = {
name: shared,
};
return next();
};

View file

@ -0,0 +1,15 @@
---
import { shared} from "../shared";
export const prerender = false;
const shared = Astro.locals.name;
---
<html>
<head>
<title>One</title>
</head>
<body>
<h1>{shared}</h1>
</body>
</html>

View file

@ -0,0 +1 @@
export const shared = 'shared';

View file

@ -201,7 +201,7 @@ describe('Hybrid rendering', () => {
adapter: nodejs({ mode: 'standalone' }),
});
await fixture.build();
const { startServer } = await await load();
const { startServer } = await load();
let res = startServer();
server = res.server;
await waitServerListen(server.server);
@ -267,7 +267,7 @@ describe('Hybrid rendering', () => {
adapter: nodejs({ mode: 'standalone' }),
});
await fixture.build();
const { startServer } = await await load();
const { startServer } = await load();
let res = startServer();
server = res.server;
await waitServerListen(server.server);
@ -315,4 +315,35 @@ describe('Hybrid rendering', () => {
assert.equal($('h1').text(), 'One');
});
});
describe('Shared modules', async () => {
before(async () => {
process.env.PRERENDER = false;
fixture = await loadFixture({
root: './fixtures/prerender/',
output: 'hybrid',
adapter: nodejs({ mode: 'standalone' }),
});
await fixture.build();
const { startServer } = await load();
let res = startServer();
server = res.server;
});
after(async () => {
await server.stop();
await fixture.clean();
delete process.env.PRERENDER;
});
it('Can render SSR route', async () => {
const res = await fetch(`http://${server.host}:${server.port}/third`);
const html = await res.text();
const $ = cheerio.load(html);
expect(res.status).to.equal(200);
expect($('h1').text()).to.equal('shared');
});
});
});