Skip to content

Commit 507197f

Browse files
fix: Revert Web Vite Config Breaking changes (#776)
1 parent e88154e commit 507197f

File tree

13 files changed

+880
-497
lines changed

13 files changed

+880
-497
lines changed

.changeset/lovely-birds-kick.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@powersync/common': minor
3+
'@powersync/react-native': minor
4+
'@powersync/web': minor
5+
---
6+
7+
Revert `event-iterator` externalization in `@powersync/common` rollup config. This now bundles `event-iterator` again in `@powersync/common`'s non Node.js export.

.changeset/slow-birds-breathe.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@powersync/web': minor
3+
---
4+
5+
Fixes regression introduced in `@powersync/web@1.28.1`. Vite users don't need to include `event-iterator` in included optimized dependencies.
6+
7+
vite.config.js
8+
9+
```diff
10+
include: [
11+
- '@powersync/web > event-iterator'
12+
]
13+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
import { setupTestDOM } from './test-setup.js';
3+
4+
describe('Customer List E2E', () => {
5+
it('should display the inserted customer "Fred" in the HTML list', async () => {
6+
// Set up the DOM structure for testing
7+
setupTestDOM();
8+
9+
// Import the main script which will execute and populate the DOM
10+
await import('../src/index.js');
11+
12+
// Trigger DOMContentLoaded if needed (script listens for this)
13+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
14+
document.dispatchEvent(new Event('DOMContentLoaded'));
15+
}
16+
17+
// Wait for the customer list to appear and contain "Fred" using vi.waitFor
18+
await vi.waitFor(() => {
19+
const customersList = document.getElementById('customers-list');
20+
expect(customersList).not.toBeNull();
21+
22+
const listItems = customersList.querySelectorAll('li');
23+
const customerNames = Array.from(listItems).map((li) => li.textContent);
24+
expect(customerNames).toContain('Fred');
25+
});
26+
});
27+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Test setup: Creates the DOM structure needed for tests
3+
* This mimics the structure in index.html
4+
*/
5+
export function setupTestDOM() {
6+
// Set up the HTML structure to match index.html
7+
document.body.innerHTML = `
8+
<h1>Vite bundling test: Check the console to see it in action!</h1>
9+
<h2>Customers:</h2>
10+
<ul id="customers-list"></ul>
11+
`;
12+
}

demos/example-vite/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
"build": "vite build",
99
"preview": "vite preview",
1010
"start": "pnpm build && pnpm preview",
11-
"test:build": "pnpm build"
11+
"prepare:isolated:test": "pnpm exec playwright install ",
12+
"test:build": "pnpm build && vitest run"
1213
},
1314
"dependencies": {
1415
"@powersync/web": "workspace:*"
1516
},
1617
"devDependencies": {
1718
"@swc/core": "~1.6.0",
19+
"@vitest/browser": "^3.2.4",
20+
"playwright": "^1.51.0",
1821
"vite": "^5.0.12",
1922
"vite-plugin-top-level-await": "^1.4.1",
20-
"vite-plugin-wasm": "^3.3.0"
23+
"vite-plugin-wasm": "^3.3.0",
24+
"vitest": "^3.2.4"
2125
}
2226
}

demos/example-vite/src/index.html

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<!doctype html>
22
<html>
3-
<head>
4-
<script type="module" src="./index.js"></script>
5-
</head>
6-
<body>
7-
Vite bundling test: Check the console to see it in action!
8-
</body>
9-
</html>
3+
4+
<head>
5+
<script type="module" src="./index.js"></script>
6+
</head>
7+
8+
<body>
9+
<h1>Vite bundling test: Check the console to see it in action!</h1>
10+
<h2>Customers:</h2>
11+
<ul id="customers-list"></ul>
12+
</body>
13+
14+
</html>

demos/example-vite/src/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { column, Schema, Table, PowerSyncDatabase, createBaseLogger } from '@powersync/web';
1+
import { PowerSyncDatabase, Schema, Table, column, createBaseLogger } from '@powersync/web';
22

33
createBaseLogger().useDefaults();
44

@@ -38,6 +38,19 @@ const openDatabase = async () => {
3838
const result = await PowerSync.getAll('SELECT * FROM customers');
3939
console.log('contents of customers: ', result);
4040

41+
// Display customers in the HTML list
42+
const customersList = document.getElementById('customers-list');
43+
if (customersList) {
44+
// Clear existing list items
45+
customersList.textContent = '';
46+
// Create and append list items
47+
result.forEach((customer) => {
48+
const listItem = document.createElement('li');
49+
listItem.textContent = customer.name || 'Unknown';
50+
customersList.appendChild(listItem);
51+
});
52+
}
53+
4154
console.log(
4255
`Attempting to connect in order to verify web workers are correctly loaded.
4356
This doesn't use any actual network credentials.

demos/example-vite/vite.config.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import wasm from 'vite-plugin-wasm';
2-
import topLevelAwait from 'vite-plugin-top-level-await';
31
import { defineConfig } from 'vite';
2+
import topLevelAwait from 'vite-plugin-top-level-await';
3+
import wasm from 'vite-plugin-wasm';
44

55
// https://vitejs.dev/config/
66
export default defineConfig({
@@ -22,5 +22,21 @@ export default defineConfig({
2222
worker: {
2323
format: 'es',
2424
plugins: () => [wasm(), topLevelAwait()]
25+
},
26+
test: {
27+
globals: true,
28+
include: ['../e2e/**/*.test.js'],
29+
maxConcurrency: 1,
30+
browser: {
31+
enabled: true,
32+
isolate: true,
33+
provider: 'playwright',
34+
headless: true,
35+
instances: [
36+
{
37+
browser: 'chromium'
38+
}
39+
]
40+
}
2541
}
2642
});

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
},
5757
"dependencies": {
5858
"async-mutex": "^0.5.0",
59-
"buffer": "^6.0.3",
6059
"event-iterator": "^2.0.0"
6160
},
6261
"devDependencies": {
@@ -66,6 +65,7 @@
6665
"@rollup/plugin-node-resolve": "^16.0.3",
6766
"@types/node": "^20.5.9",
6867
"@types/uuid": "^9.0.1",
68+
"buffer": "^6.0.3",
6969
"rollup": "^4.52.5",
7070
"cross-fetch": "^4.1.0",
7171
"js-logger": "^1.6.1",

packages/common/rollup.config.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as path from 'node:path';
2-
31
import commonjs from '@rollup/plugin-commonjs';
42
import inject from '@rollup/plugin-inject';
53
import json from '@rollup/plugin-json';
@@ -33,7 +31,7 @@ function defineBuild(isNode) {
3331
})
3432
]
3533
],
36-
external: ['async-mutex', 'bson', 'buffer/', 'event-iterator']
34+
external: ['async-mutex', 'bson', isNode ? 'event-iterator' : undefined]
3735
};
3836
}
3937

0 commit comments

Comments
 (0)