Skip to content

Commit c0c996f

Browse files
committed
web: Fix SQL.js WASM path issue on GitHub Pages
- Redirect /sql-wasm.wasm requests to ./sql-wasm.wasm - Fix both fetch() and XMLHttpRequest overrides - Addresses SQLDelight GitHub issues #5978 and #4782 - SQL.js was trying to load WASM from root path (404) instead of correct path - This should resolve the WebAssembly compilation error
1 parent 7016656 commit c0c996f

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

app/web/webpack.config.d/sqljs-config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ class GitHubPagesWasmPlugin {
125125
console.log('Fetch called with URL:', url);
126126
if (typeof url === 'string' && url.endsWith('.wasm')) {
127127
console.log('Intercepting WASM request:', url);
128-
return originalFetch(url, options).then(response => {
128+
129+
// Fix the SQL.js WASM path issue - redirect root path to correct path
130+
let correctedUrl = url;
131+
if (url === '/sql-wasm.wasm' || url.endsWith('/sql-wasm.wasm')) {
132+
correctedUrl = './sql-wasm.wasm';
133+
console.log('🔧 Redirecting SQL.js WASM request from', url, 'to', correctedUrl);
134+
}
135+
136+
return originalFetch(correctedUrl, options).then(response => {
129137
console.log('WASM response status:', response.status);
130138
console.log('WASM response headers:', response.headers.get('content-type'));
131139
if (response.ok) {
@@ -167,6 +175,15 @@ class GitHubPagesWasmPlugin {
167175
XMLHttpRequest.prototype.send = function(data) {
168176
if (this._url && this._url.endsWith('.wasm')) {
169177
console.log('Intercepting XHR WASM request:', this._url);
178+
179+
// Fix the SQL.js WASM path issue - redirect root path to correct path
180+
if (this._url === '/sql-wasm.wasm' || this._url.endsWith('/sql-wasm.wasm')) {
181+
console.log('🔧 Redirecting XHR SQL.js WASM request from', this._url, 'to ./sql-wasm.wasm');
182+
this._url = './sql-wasm.wasm';
183+
// Re-open with corrected URL
184+
this.open('GET', this._url, true);
185+
}
186+
170187
const originalOnReadyStateChange = this.onreadystatechange;
171188
this.onreadystatechange = function() {
172189
if (this.readyState === 4 && this.status === 200) {

0 commit comments

Comments
 (0)