Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

fix(Web): the generated entities does not compile for web platform#127

Open
danielgomezriconeon wants to merge 10 commits intoisar-community:v3from
NEONSCREENS:fix/web-compilation-issue-80
Open

fix(Web): the generated entities does not compile for web platform#127
danielgomezriconeon wants to merge 10 commits intoisar-community:v3from
NEONSCREENS:fix/web-compilation-issue-80

Conversation

@danielgomezriconeon
Copy link

@danielgomezriconeon danielgomezriconeon commented Jul 3, 2025

Fixes issue:

Done:

  • Replace compile-time xxh3 hash generation with runtime function generators
  • Add web-safe hash function that works across all platforms without large integers
  • Modify ObjectInfo, ObjectIndex, and ObjectLink to use idGenerator instead of id
  • Update schema generators to use function-based ID generation
  • Add a Makefile and some tests to keep this in order over time:
$ make test
🧪 Running isar_generator tests...
00:00 +16: All tests passed!
✅ Generator tests completed!
🧪 Running isar package tests...
00:00 +10: All tests passed!
✅ Isar package tests completed!
🌐 Web compilation fix tests completed successfully!
✅ All web compilation fix tests completed successfully!

Caution

BREAKING CHANGE: Schema objects now use idGenerator functions instead of static id fields

Context

I saw some work over time but none of those worked for me:

…rals

- Replace compile-time xxh3 hash generation with runtime function generators
- Add web-safe hash function that works across all platforms without large integers
- Modify ObjectInfo, ObjectIndex, and ObjectLink to use idGenerator instead of id
- Update schema generators to use function-based ID generation
- Fixes issue isar-community#80 where apps including Isar couldn't compile for web

BREAKING CHANGE: Schema objects now use idGenerator functions instead of static id fields
- Add idGenerator field to Schema, IndexSchema, and LinkSchema classes
- Maintain backward compatibility with existing id field
- Support both compile-time id and runtime idGenerator approaches
- Update constructors to accept either id or idGenerator parameters
- Remove const from Schema, CollectionSchema, IndexSchema, and LinkSchema constructors
- Change generated schema declarations from const to final
- This allows idGenerator function expressions to be used in constructors
- Fixes compilation errors with function expressions in const contexts
- Add web-safe hash function tests covering consistency, range limits, and distribution
- Add object info generator tests for idGenerator string generation
- Add schema backward compatibility tests for hash function behavior
- Add regression tests to ensure no performance degradation
- Add integration tests for web compilation scenarios (note: some disabled due to build_test compatibility issues)
- Tests verify that generated code stays within JavaScript safe integer range
- Tests ensure consistent ID generation across platforms
- All core functionality tests pass successfully
- Add Makefile with organized command structure and help system
- Include test commands for web compilation fix validation
- Add development commands for deps, formatting, linting
- Add cleanup and status commands for project maintenance
- Default 'make' command shows help with all available commands
- Specific commands:
  - make test: Run web compilation fix tests
  - make help: Display help message
  - make test-all: Run comprehensive test suite
  - make deps: Install dependencies
  - make format/lint: Code quality commands
  - make clean: Cleanup build artifacts

Commands are organized by category with clear descriptions and examples.
@danielgomezriconeon danielgomezriconeon marked this pull request as ready for review July 3, 2025 15:20
@danielgomezriconeon danielgomezriconeon changed the title fix(generator): resolve web compilation issue with large integer lite… fix(Web): the generated entities does not compile for web platform Jul 3, 2025
- Reduce Makefile complexity to focus on core requirements
- Keep only 'test' and 'help' commands as requested
- Default 'make' command shows help message
- 'make test' runs web compilation fix tests
- Clean, simple interface with clear output formatting
- Change 'make test' to run all tests across all packages
- Handle problematic tests with build_test dependency issues gracefully
- Include working tests from isar_generator (web_safe_hash_test, object_info_test)
- Include all tests from isar package
- Attempt to run tests from isar_inspector and isar_test with fallback messages
- Provide clear feedback when tests fail or are unavailable
- Update help text to reflect that it runs all tests
@azielstyle
Copy link

azielstyle commented Jul 4, 2025

thank you, I just test it and I finnally can run my project on web!

@danielgomezriconeon
Copy link
Author

danielgomezriconeon commented Jul 7, 2025

It works for web but I tried adding this on an android build via overrides and I get errors:

pubdev.yaml

dependencies:
  // ...
  isar:
    version: 3.1.8
    hosted: https://pub.isar-community.dev/
  isar_flutter_libs: # contains Isar Core
    version: 3.1.8
    hosted: https://pub.isar-community.dev/

dev_dependencies:
  // ...
  isar_generator:
    version: 3.1.8
    hosted: https://pub.isar-community.dev/
    
dependency_overrides:
  isar:
    git:
      url: https://github.com/NEONSCREENS/mobile-flutter-isar
      ref: v3.0-web-fix-tmp
      path: packages/isar
  isar_flutter_libs:
    git:
      url: https://github.com/NEONSCREENS/mobile-flutter-isar
      ref: v3.0-web-fix-tmp
      path: packages/isar_flutter_libs
  isar_generator:
    git:
      url: https://github.com/NEONSCREENS/mobile-flutter-isar
      ref: v3.0-web-fix-tmp
      path: packages/isar_generator

Error:

IsarError: Could not initialize IsarCore library for processor architecture "android_arm64". If you create a Flutter app, make sure to add isar_flutter_libs to your dependencies.
IsarError: Incorrect Isar Core version: Required 3.1.8 found 3.1.0+1. Make sure to use the latest isar_flutter_libs. If you have a Dart only project, make sure that old Isar Core binaries are deleted.
	#0      initializeCoreBinary (package:isar/src/native/isar_core.dart:78:7)
	#1      openIsar (package:isar/src/native/open.dart:81:3)
	#2      Isar.open (package:isar/src/isar.dart:107:12)

I think it is related to add add those as github references since it has some kind of internal builds (.so)

@danielgomezriconeon
Copy link
Author

hey @vicenterusso ping

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants