Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5 @next.148 broke Layercake #11934

Closed
vipero07 opened this issue Jun 6, 2024 · 3 comments · Fixed by #12091
Closed

Svelte 5 @next.148 broke Layercake #11934

vipero07 opened this issue Jun 6, 2024 · 3 comments · Fixed by #12091
Labels
awaiting submitter needs a reproduction, or clarification
Milestone

Comments

@vipero07
Copy link

vipero07 commented Jun 6, 2024

Describe the bug

After upgrading from 5.0.0-next.147 to 5.0.0-next.148 I get the following error in browser when navigating away from a sveltekit page that has a layercake component on it.

image

This issue persists in next.150 as well.

Reproduction

I am going to see if I can fully reproduce this outside of my project (its unfortunately rather large and complex so this may take some time) but the minimum dependencies are the following.

  "dependencies": {
    "@sveltejs/kit": "2.5.10",
    "@sveltejs/vite-plugin-svelte": "3.1.1",
    "layercake": "8.3.0",
    "svelte": "5.0.0-next.148",
    "vite": "5.2.12"
  },

Then you just have two page routes, one with a layercake component, navigate to it, and away from it.

https://replit.com/@yodaissmart/Svelte-500next148-error?v=1
Click the chart link in the nav bar, then click home.

Logs

TypeError: Cannot read properties of undefined (reading 'delete')
    at chunk-W4736B2D.js?v=5c3605ec:2198:18
    at execute_effect_teardown (chunk-HMLMMEOZ.js?v=5c3605ec:2028:16)
    at destroy_effect (chunk-HMLMMEOZ.js?v=5c3605ec:2048:3)
    at destroy_effect_children (chunk-HMLMMEOZ.js?v=5c3605ec:1274:5)
    at destroy_effect (chunk-HMLMMEOZ.js?v=5c3605ec:2040:3)
    at destroy_effect_children (chunk-HMLMMEOZ.js?v=5c3605ec:1274:5)
    at destroy_effect (chunk-HMLMMEOZ.js?v=5c3605ec:2040:3)
    at destroy_effect_children (chunk-HMLMMEOZ.js?v=5c3605ec:1274:5)
    at destroy_effect (chunk-HMLMMEOZ.js?v=5c3605ec:2040:3)
    at destroy_effect_children (chunk-HMLMMEOZ.js?v=5c3605ec:1274:5)

The specific location of that error is the line listeners2.delete(listener); in the following chunk.

// node_modules/svelte/src/internal/client/dom/elements/bindings/size.js
var _listeners, _observer, _options, _getObserver, getObserver_fn;
var _ResizeObserverSingleton = class _ResizeObserverSingleton {
  /** @param {ResizeObserverOptions} options */
  constructor(options) {
    __privateAdd(this, _getObserver);
    /** */
    __privateAdd(this, _listeners, /* @__PURE__ */ new WeakMap());
    /** @type {ResizeObserver | undefined} */
    __privateAdd(this, _observer, void 0);
    /** @type {ResizeObserverOptions} */
    __privateAdd(this, _options, void 0);
    __privateSet(this, _options, options);
  }
  /**
   * @param {Element} element
   * @param {(entry: ResizeObserverEntry) => any} listener
   */
  observe(element2, listener) {
    var listeners = __privateGet(this, _listeners).get(element2) || /* @__PURE__ */ new Set();
    listeners.add(listener);
    __privateGet(this, _listeners).set(element2, listeners);
    __privateMethod(this, _getObserver, getObserver_fn).call(this).observe(element2, __privateGet(this, _options));
    return () => {
      var listeners2 = __privateGet(this, _listeners).get(element2);
      listeners2.delete(listener);
      if (listeners2.size === 0) {
        __privateGet(this, _listeners).delete(element2);
        __privateGet(this, _observer).unobserve(element2);
      }
    };
  }
};

System Info

System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 875.78 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.13.1 - /private/var/folders/14/ghm2196s181_vf_0g1425s7m0000gn/T/xfs-ca02c7c1/node
    Yarn: 4.1.1 - /private/var/folders/14/ghm2196s181_vf_0g1425s7m0000gn/T/xfs-ca02c7c1/yarn
    npm: 10.5.2 - ~/.volta/tools/image/node/20.13.1/bin/npm
  Browsers:
    Brave Browser: 121.1.62.156
    Safari: 17.4.1
  npmPackages:
    svelte: 5.0.0-next.148 => 5.0.0-next.148

Severity

blocking an upgrade

@Conduitry Conduitry added the awaiting submitter needs a reproduction, or clarification label Jun 6, 2024
@vipero07
Copy link
Author

vipero07 commented Jun 6, 2024

A simple solution is to just ensure listeners2 is not undefined before calling delete on it. Though this may result in a memory leak, I'm not familiar enough with the underlying code.

@vipero07
Copy link
Author

vipero07 commented Jun 6, 2024

Here is a repl https://replit.com/@yodaissmart/Svelte-500next148-error?v=1
Click the chart link in the nav bar, then click home.

@asadbek2304
Copy link

Any updates on this?

dummdidumm added a commit that referenced this issue Jun 19, 2024
The `update` function could cause a read, which would end up being tracked in the effect, and said effect would then run multiple times when it should only run once

fixes #11934
fixes #12028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants