Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: double modules hazard by preferring relative paths #645

Merged
merged 30 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions e2e/07_router_standalone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const { version } = createRequire(import.meta.url)(
);

async function testRouterExample(page: Page, port: number) {
await waitPort({
port,
});
await waitPort({ port });

await page.goto(`http://localhost:${port}`);
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible();
Expand Down Expand Up @@ -78,9 +76,7 @@ test.describe('07_router standalone', () => {
const port = await getFreePort();
const cp = exec(
`node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} start --port ${port}`,
{
cwd: standaloneDir,
},
{ cwd: standaloneDir },
);
debugChildProcess(cp, fileURLToPath(import.meta.url));
await testRouterExample(page, port);
Expand All @@ -92,9 +88,7 @@ test.describe('07_router standalone', () => {
const port = await getFreePort();
const cp = exec(
`node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} dev --port ${port}`,
{
cwd: standaloneDir,
},
{ cwd: standaloneDir },
);
debugChildProcess(cp, fileURLToPath(import.meta.url), [
/WebSocket server error: Port is already in use/,
Expand Down
20 changes: 5 additions & 15 deletions e2e/examples-smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ for (const cwd of examples) {
});
}
port = await getFreePort();
cp = exec(`${command} --port ${port}`, {
cwd,
});
cp = exec(`${command} --port ${port}`, { cwd });
debugChildProcess(cp, fileURLToPath(import.meta.url));
await waitPort({
port,
});
await waitPort({ port });
});

test.afterAll(async () => {
Expand Down Expand Up @@ -107,14 +103,10 @@ for (const cwd of examples) {

test.beforeAll(async () => {
if (build) {
execSync(`node ${waku} ${build}`, {
cwd,
});
execSync(`node ${waku} ${build}`, { cwd });
}
port = await getFreePort();
cp = exec(`node ${waku} ${command} --port ${port}`, {
cwd,
});
cp = exec(`node ${waku} ${command} --port ${port}`, { cwd });
cp.stdout?.on('data', (data) => {
info(`${port} stdout: ${data}`);
console.log(`${port} stdout: `, `${data}`);
Expand All @@ -130,9 +122,7 @@ for (const cwd of examples) {
error(`${port} stderr: ${data}`);
console.error(`${port} stderr: `, `${data}`);
});
await waitPort({
port,
});
await waitPort({ port });
});

test.afterAll(async () => {
Expand Down
3 changes: 3 additions & 0 deletions e2e/fixtures/ssr-context-provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SSR Context Provider

To cover https://github.com/dai-shi/waku/issues/631 case
22 changes: 22 additions & 0 deletions e2e/fixtures/ssr-context-provider/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ssr-context-provider",
"version": "0.1.0",
"type": "module",
"private": true,
"scripts": {
"dev": "waku dev",
"build": "waku build",
"start": "waku start"
},
"dependencies": {
"react": "19.0.0-canary-e3ebcd54b-20240405",
"react-dom": "19.0.0-canary-e3ebcd54b-20240405",
"react-server-dom-webpack": "19.0.0-canary-e3ebcd54b-20240405",
"waku": "workspace:*"
},
"devDependencies": {
"@types/react": "18.2.74",
"@types/react-dom": "18.2.24",
"typescript": "5.4.4"
}
}
12 changes: 12 additions & 0 deletions e2e/fixtures/ssr-context-provider/src/components/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ContextProvider } from './context-provider.js';
import { ContextConsumer } from './context-consumer.js';

export default function App() {
return (
<div>
<ContextProvider>
<ContextConsumer />
</ContextProvider>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use client';

import { useContext, useEffect, useState } from 'react';

import { Context } from './context-provider.js';

export const ContextConsumer = () => {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
const value = useContext(Context);
return (
<>
{mounted && <div data-testid="mounted">true</div>}
<div data-testid="value">{value}</div>;
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use client';

import { createContext } from 'react';
import type { ReactNode } from 'react';

export const Context = createContext('original');

export const ContextProvider = ({ children }: { children: ReactNode }) => {
return <Context.Provider value="provider value">{children}</Context.Provider>;
};
29 changes: 29 additions & 0 deletions e2e/fixtures/ssr-context-provider/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference types="react/experimental" />

import { defineEntries } from 'waku/server';
import { Slot } from 'waku/client';

import App from './components/app.js';

export default defineEntries(
// renderEntries
async () => {
return {
App: <App />,
};
},
// getBuildConfig
async () => [{ pathname: '/', entries: [{ input: '' }] }],
// getSsrConfig
async (pathname) => {
switch (pathname) {
case '/':
return {
input: '',
body: <Slot id="App" />,
};
default:
return null;
}
},
);
17 changes: 17 additions & 0 deletions e2e/fixtures/ssr-context-provider/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { StrictMode } from 'react';
import { createRoot, hydrateRoot } from 'react-dom/client';
import { Root, Slot } from 'waku/client';

const rootElement = (
<StrictMode>
<Root>
<Slot id="App" />
</Root>
</StrictMode>
);

if (document.body.dataset.hydrate) {
hydrateRoot(document.body, rootElement);
} else {
createRoot(document.body).render(rootElement);
}
17 changes: 17 additions & 0 deletions e2e/fixtures/ssr-context-provider/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"composite": true,
"strict": true,
"target": "esnext",
"downlevelIteration": true,
"esModuleInterop": true,
"module": "nodenext",
"skipLibCheck": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"types": ["react/experimental"],
"jsx": "react-jsx",
"rootDir": "./src",
"outDir": "./dist"
}
}
15 changes: 3 additions & 12 deletions e2e/rsc-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,12 @@ for (const { build, command } of commands) {

test.beforeAll(async () => {
if (build) {
execSync(`node ${waku} ${build}`, {
cwd,
});
execSync(`node ${waku} ${build}`, { cwd });
}
port = await getFreePort();
cp = exec(`node ${waku} ${command} --port ${port}`, {
cwd,
});
cp = exec(`node ${waku} ${command} --port ${port}`, { cwd });
debugChildProcess(cp, fileURLToPath(import.meta.url));
await waitPort({
port,
});
await waitPort({ port });
});

test.afterAll(async () => {
Expand All @@ -54,9 +48,7 @@ for (const { build, command } of commands) {

test('basic', async ({ page }) => {
await page.goto(`http://localhost:${port}/`);

await expect(page.getByTestId('app-name')).toHaveText('Waku');

await expect(
page.getByTestId('client-counter').getByTestId('count'),
).toHaveText('0');
Expand All @@ -68,7 +60,6 @@ for (const { build, command } of commands) {
await expect(
page.getByTestId('client-counter').getByTestId('count'),
).toHaveText('2');

await expect(
page.getByTestId('server-ping').getByTestId('pong'),
).toBeEmpty();
Expand Down
12 changes: 3 additions & 9 deletions e2e/rsc-router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,12 @@ for (const { build, command } of commands) {

test.beforeAll(async () => {
if (build) {
execSync(`node ${waku} ${build}`, {
cwd,
});
execSync(`node ${waku} ${build}`, { cwd });
}
port = await getFreePort();
cp = exec(`node ${waku} ${command} --port ${port}`, {
cwd,
});
cp = exec(`node ${waku} ${command} --port ${port}`, { cwd });
debugChildProcess(cp, fileURLToPath(import.meta.url));
await waitPort({
port,
});
await waitPort({ port });
});

test.afterAll(async () => {
Expand Down
12 changes: 3 additions & 9 deletions e2e/ssr-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,12 @@ for (const { build, command } of commands) {

test.beforeAll(async () => {
if (build) {
execSync(`node ${waku} ${build}`, {
cwd,
});
execSync(`node ${waku} ${build}`, { cwd });
}
port = await getFreePort();
cp = exec(`node ${waku} ${command} --port ${port}`, {
cwd,
});
cp = exec(`node ${waku} ${command} --port ${port}`, { cwd });
debugChildProcess(cp, fileURLToPath(import.meta.url));
await waitPort({
port,
});
await waitPort({ port });
});

test.afterAll(async () => {
Expand Down
68 changes: 68 additions & 0 deletions e2e/ssr-context-provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { expect } from '@playwright/test';
import { execSync, exec, ChildProcess } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import waitPort from 'wait-port';
import { debugChildProcess, getFreePort, terminate, test } from './utils.js';
import { rm } from 'node:fs/promises';

const waku = fileURLToPath(
new URL('../packages/waku/dist/cli.js', import.meta.url),
);

const commands = [
{
command: 'dev',
},
{
build: 'build',
command: 'start',
},
];

const cwd = fileURLToPath(
new URL('./fixtures/ssr-context-provider', import.meta.url),
);

for (const { build, command } of commands) {
test.describe(`ssr-context-provider: ${command}`, () => {
let cp: ChildProcess;
let port: number;
test.beforeAll('remove cache', async () => {
await rm(`${cwd}/dist`, {
recursive: true,
force: true,
});
});

test.beforeAll(async () => {
if (build) {
execSync(`node ${waku} ${build}`, { cwd });
}
port = await getFreePort();
cp = exec(`node ${waku} ${command} --port ${port}`, { cwd });
debugChildProcess(cp, fileURLToPath(import.meta.url));
await waitPort({ port });
});

test.afterAll(async () => {
await terminate(cp.pid!);
});

test('show context value', async ({ page }) => {
await page.goto(`http://localhost:${port}/`);
await page.waitForSelector('[data-testid="mounted"]');
await expect(page.getByTestId('value')).toHaveText('provider value');
});

test('no js environment', async ({ browser }) => {
const context = await browser.newContext({
javaScriptEnabled: false,
});
const page = await context.newPage();
await page.goto(`http://localhost:${port}/`);
await expect(page.getByTestId('value')).toHaveText('provider value');
await page.close();
await context.close();
});
});
}
12 changes: 3 additions & 9 deletions e2e/ssr-swr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,12 @@ for (const { build, command } of commands) {

test.beforeAll(async () => {
if (build) {
execSync(`node ${waku} ${build}`, {
cwd,
});
execSync(`node ${waku} ${build}`, { cwd });
}
port = await getFreePort();
cp = exec(`node ${waku} ${command} --port ${port}`, {
cwd,
});
cp = exec(`node ${waku} ${command} --port ${port}`, { cwd });
debugChildProcess(cp, fileURLToPath(import.meta.url));
await waitPort({
port,
});
await waitPort({ port });
});

test.afterAll(async () => {
Expand Down
Loading
Loading