iTwin / viewer

Monorepo that contains the iTwin Viewer npm packages and their related packages
MIT License
24 stars 15 forks source link

Blank connection reporting "IModel is not open for rpc" error #301

Closed Alfonso-Martello closed 9 months ago

Alfonso-Martello commented 9 months ago

Describe the bug Opening the web viewer with a blank connection causes an error "Bad Request: IModel is not open for rpc". Naturally, blank connections do not have an iModel to interface with.

I think I tracked down where this error is coming from. It appears to be coming from the newly added syncSelectionScopeList function that was added as part of this PR#297. Specifically, in the getSelectionScopes call, the function iModel.getRpcProps is called. getRpcProps throws the error if the iModelConnection is closed (and blank connections are always closed).

My guess is that the fix is to add logic to not sync selection scopes when the connection is blank, but I see the PR was created to replicate behavior that was removed in 4.x and I'm unsure how the previous behavior treated blank connections.

To Reproduce Steps to reproduce the behavior:

  1. Go to this sandbox: viewer-blank-connection-sandbox. It is just the sandbox's Geometry Template sandbox with no modifications.
  2. Export the sandbox to a local project. To export a. Click the three dots in the top right of the sandbox and from the dropdown, choose the Export Sandbox option. image b. In the popup that appears, click the Sandbox Download is ready link in the bottom left. This will download the sandbox as a zipped folder. image
  3. Unzip the folder.
  4. Navigate to the folder. Create a new app client (I recommend step 3 of the quick start for this) and a new iTwin (I recommend My iTwins for this). Supply your app client and iTwin in the .env file.
  5. Run npm install.
  6. Run npm run start.
  7. Observe the error.

Expected behavior Blank connections should not cause rpc errors to be thrown.

Screenshots image

Desktop:

OS: Windows 11 Browser: Chrome iTwin.js Version: Reproduced on @itwin/web-viewer-react: 4.2.0 & @itwin/viewer-react: 4.5.0.