Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

Worker/Worker-Fallback + setFetchOptions is not working with Vite-bundled web app #134

@srxtw

Description

@srxtw

Issue
In the latest build (1.3.0) and main branch, the package generated from package.json is not working for network requests in vite-based web app.

When running by default in worker mode, the statement
setFetchOptionsUpdateCallback is completely missing in bundled ogclient js in browser, as a result, worker won't get updated fetch option like headers.

When running with fallback mode enableFallbackWithoutWorker, addTaskHandler is executed but main thread can never receive the event to proceed with network request. Investigated the OGCClient bundled js in browser, and there are two fallback event targets

// node_modules/@camptocamp/ogc-client/dist/worker/index.js
var fallbackEventTarget = new EventTarget();
// node_modules/@camptocamp/ogc-client/dist/worker/utils.js
var fallbackEventTarget2 = new EventTarget();

It seems these issues are directly related to how package is built and worker\index.js is excluded in build:browser

Working Workarounds we've investigated

  1. Build package with main branch and use latest dist/dist-node.js in web app, this commit has removed node dependency, in 1.3.0, we are still getting node dependency issue with web app + dist-node.js
    • Add another dist-bundled by removing -not -path '*worker/index.ts'
      Example
    • Above step will trigger JS issue when creating web worker in npm run dev.
      In vite.config.js, add @camptocamp/ogc-client to exclude list of optimizeDeps
    • In vite.config.js, add below alias mapping.
      '@camptocamp/ogc-client/bundled': path.resolve(__dirname, 'node_modules/@camptocamp/ogc-client/dist-bundled/index.js'),
      '@rgrove/parse-xml': path.resolve(__dirname, 'node_modules/@rgrove/parse-xml/dist/index.js'),
      Example
      With workaround 2, both worker/fallback mode will send network request with proper customized fetch options.

Summary
In 1.2.0, The worker +setFetchOption is not working either, but worker-fallback in main thread can receive event to proceed with network request. We believe this is a regression.
We'd like to consult with contributor here and need a formal solution for ogc-client for both Worker + Worker-Fallback with customized fetch option.

Steps to reproduce.

  1. Use AI to generate any web app like React+Vite Example
  2. Import npm library 1.3.0
    3 In the web app, run below
    setFetchOptions(sampleOptions);
    const endpoint = new WmtsEndpoint('https://mrdata.usgs.gov/mapcache/wmts/');
    await endpoint.isReady();
  3. Fetch Options like headers do not appear in the outgoing Request for worker.
  4. Repeat 3. but run enableFallbackWithoutWorker(); before setFetchOption
  5. Listener on Main thread does not receive event and there is no network request.

Similar issues:
#99

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions