Skip to content

Chrome Extension Background Page and useEffect Not Triggered #16629

@mikecann

Description

@mikecann

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When using useEffect from a background page in a chrome extension the body of the effect isnt triggered.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

See the demo project here: https://github.com/mikecann/bgpage-hooks-issue

What is the expected behavior?

useEffect should be triggered

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

It stopped working somewhere between react 16.8 and 16.9 , you can change the react and react_dom version in the demo project and see that it works as expected in 16.8

Workaround

For now the issue can be worked around as demonstrated: https://github.com/mikecann/bgpage-hooks-issue/blob/master/bg.tsx#L5

So im not really sure whats going on but perhaps because background pages arent actually visually rendered to the screen then React has optimized things so that effects arent triggered?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions