Coder Social home page Coder Social logo

Comments (4)

tofumatt avatar tofumatt commented on May 28, 2024 1

Will do, sorry I haven't tried the fix sooner and thanks so much for your work looking into it and fixing it with the little info I gave! Just been busy with another part of the project but I'll try it this week hopefully 😄

from react-redux-loading-bar.

tofumatt avatar tofumatt commented on May 28, 2024 1

Just wanted to let you know I tested this on our production build (locally) and it seems to have worked perfectly. Thanks so much for tracking this down and the quick fix! 😄

from react-redux-loading-bar.

mironov avatar mironov commented on May 28, 2024

@tofumatt Thanks for the bug report, it was a tricky one!

The problem can be reproduced with Server Side Rendering and strict Content Security Policy for styles (i.e. style-src doesn't have 'unsafe-inline').

Some context:
I intentionally haven't introduced any dependencies or CSS files into the loading bar to keep it lightweight and easy to configure. It can be used without any preprocessors.

When the browser loads an SSR page, it blocks inline styles on its elements. Once Loading Bar kicks in, it alters its inline styles to emulate progress. Turned out that style attributes that were initially blocked will not be applied to the element unless they change.

Inline styles in 2.8.2:

  var style = {
    width: this.state.percent + '%',
    transition: 'width ' + ANIMATION_TIME + 'ms linear',
    opacity: '1'
  }

  if (this.shouldShow()) {
    style.opacity = '1';
  } else {
    style.opacity = '0';
  }

width and opacity are dynamic attributes. The transition attribute will never be applied to the element as it was initially blocked by CSP and never changes. However, the animation will be shown because width and opacity combined with custom CSS class for color, height, and positioning is enough to make it work.

Inline styles in 2.9.0:

  var style = {
    opacity: '1',
    transform: 'scaleX(' + this.state.percent / 100 + ')',
    transformOrigin: 'left',
    transition: 'transform ' + ANIMATION_TIME + 'ms linear',
    width: '100%',
    willChange: 'transform, opacity'
  }

  if (this.shouldShow()) {
    style.opacity = '1';
  } else {
    style.opacity = '0';
  }

Static styles as transformOrigin, transition, width, willChange will be ignored.
That change in animation mechanics in 2.9.0 revealed the problem.

Please give v2.9.1 a try.
It renders a placeholder on the server side and replaces it with the actual Loading Bar with proper styles after mount. That should not trigger CSP warnings on initial page render and fix the animation.

from react-redux-loading-bar.

mironov avatar mironov commented on May 28, 2024

@tofumatt I'm going to close this issue as I think it is resolved in v2.9.1.
Feel free to reopen if the fix didn't work for you.

from react-redux-loading-bar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.