question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Event for non-legacy browsers with `onlyLegacy: true`

See original GitHub issue

Hi, thank you for building + maintaining such a great ponyfill!

I have some code (initializing a Vue app) that I want to have run as early as possible, but not before the cssVars call completes on legacy browsers. I also don’t want to have to add onlyLegacy: false because I don’t want extra work to be done in non-legacy browsers. However, handlers like onComplete don’t trigger at all in non-legacy browsers, so adding my initialization code to onComplete means that it never runs in non-legacy browsers.

Could you add a handler that triggers after cssVars call is done, even in non-legacy browsers and with onlyLegacy: true set? It could either be a handler called only when cssVars bails early or one that’s called 100% of the time.

Thank you!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jhildenbiddlecommented, Feb 28, 2020

Sounds good to me then. I’ll take care of this early next week.

Thanks for the quick feedback, everyone!

1reaction
jhildenbiddlecommented, Feb 27, 2020

Makes sense. Here are my initial thoughts:

  • Callback to be named onDone
  • Last callback invoked by the ponyfill (after onComplete, if applicable)
  • Invoked in all browsers
  • Returns two values: hasNativeSupport and benchmark

Examples

cssVars({
  onDone(hasNativeSupport, benchmark) {
    // All browsers...
    console.log('Benchmark: ' + benchmark);
  }
});

The onComplete callback will continue to be where you access the CSS output, DOM elements, and custom property key/value pairs processed by the ponyfill, while the onDone callback can be used to invoke post-ponyfill code in both modern and legacy browsers:

cssVars({
  onComplete(cssText, styleElms, cssVariables) {
    // Legacy browsers...
  },
  onDone(hasNativeSupport, benchmark) {
    // All browsers...
    console.log('Benchmark: ' + benchmark);
  }
});

If you don’t need to access the values returned by the onComplete callback, you can move all post-ponyfill logic into the onDone callback and use the hasNativeSupport argument to target modern and/or legacy browsers:

cssVars({
  onDone(hasNativeSupport, benchmark) {
    // All browsers...
    console.log('Benchmark: ' + benchmark);

    // Modern browsers...
    if (hasNativeSupport) {
      console.log('Native Support');
    }
    // Legacy browsers...
    else {
      console.log('Legacy');
    }
  }
});

The only bummer is that this will require a major version bump since the benchmark value is being moved from the onComplete callback to the onDone callback.

Thoughts?

Pinging @pseudoramble, @freitasskeeled, and @evry-johber since they created issues related to this same topic earlier.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css-vars-ponyfill - GitHub Pages
onlyLegacy is false , modern browsers with native support for CSS custom ... XML object by setting properties, calling methods, or adding event...
Read more >
Passive event listeners | Can I use... Support tables for HTML5 ...
Event listeners created with the passive: true option cannot cancel ( preventDefault() ) the events they receive. Primarily intended to be used with...
Read more >
Diff - af526ec9c36dfbb3c244ad03f8df79311e5ba03c^2 ... - Google Git
+ * + * @param legacy true if only legacy advertisements will be returned + */ + public Builder setLegacy(boolean legacy) { +...
Read more >
https://www.ietf.org/tools/idnits?url=https://www....
Each node may have 162 zero, one or more source identifiers (SSRCs) used to either identify 163 a real media source such as...
Read more >
Pamela, - Intel Communities
In the non-Legacy builds those core plugins are included in the emulator and the ... There is no longer a legacy build for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found