gristlabs / grist-static

Showing Grist spreadsheets on a static website, without a special backend.
https://gristlabs.github.io/grist-static/
Apache License 2.0
82 stars 0 forks source link

Add initialData argument to bootstrapGrist with URL of file to import #14

Closed alexmojaki closed 1 year ago

alexmojaki commented 1 year ago

Uses https://github.com/gristlabs/grist-core/pull/564

Visit http://localhost:3030/page/index_initial_data.html to test.

This almost works, but as it applies the actions it runs into a version of https://github.com/gristlabs/grist-static/issues/5:

Screenshot from 2023-07-10 15-20-11

It seems that the ['RemoveRecord', '_grist_Tables', 2] action to remove the temporary GristHidden_import table is not properly processed before ['AddRecord', '_grist_Tables', 2, {tableId: 'StudentData', primaryViewId: 0}].

I've poked around and not been able to understand what's going wrong. It smells like a race condition, maybe something about transactions. @paulfitz I need help with this.

paulfitz commented 1 year ago

At first glance, I'm suspicious of SQLiteDB.runEach, it looks weird and complicated, and is used when deleting columns. Might have some bug when not running on node-sqlite3. Will look into it.

paulfitz commented 1 year ago

I found this lurking, a parameter nested in an array - node-sqlite3 is happy with this, but sql.js is not:

@@ -1093,7 +1093,7 @@ export class DocStorage implements ISQLiteDB, OnDemandStorage {
   public _process_RemoveRecord(tableId: string, rowId: string): Promise<RunResult> {
     const sql = "DELETE FROM " + quoteIdent(tableId) + " WHERE id=?";
     debuglog("RemoveRecord SQL: " + sql, [rowId]);
-    return this.run(sql, [rowId]);
+    return this.run(sql, rowId);
   }

So looks like record removal was not working, at the database level - could see how that would cause a lot of problems :). Making a PR to grist-core. In future, I bet we could run a batch of grist-core browser tests against grist-static with a bit of tweaking.

Update: https://github.com/gristlabs/grist-core/pull/566

alexmojaki commented 1 year ago

Thanks @paulfitz! This works now. Should I convert https://github.com/gristlabs/grist-core/pull/564 to a diff?