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.

Container query not working after a react-route navigation.

See original GitHub issue

I have a little demo here: https://github.com/Enebz/container-query-demo

Here, I noticed that the container queries doesn’t work after navigating to a new page (using react-router v6)

When you are located in / and click the button that forwards you to /demo The grid of items appears with a column width of 3, which is the default style (mobile first) and not the correct container query style even if you are on a wide screen.

The container queries are located at: https://github.com/Enebz/container-query-demo/blob/master/src/index.css#L142

If you open devtools and resize the width of the container, the container queries work and the grid goes to the correct grid column size.

NOTE You probably noticed that the container I am assigning container-type: size; to is of width: 100% and the same width as the screen, so why not just use @media? Well, this is only a demo and in my real project I have a sidebar which “pushes” the main content, such that I need a container query to correctly set the grid-column size.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

2reactions
devknollcommented, Aug 16, 2022

This should be addressed by the latest version of the polyfill (currently in alpha). Please give it a try. I’m going to close this issue for now, but I would be happy to reopen it if you’re still running into problems.

Thank you!

1reaction
martinszeltinscommented, Aug 6, 2022

Seems like there’s no exported function to re-initialize

You can fork the lib and add a re-initialize function. That’s what I did.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-query and navigation (react-router-dom) returns blank ...
When I'm navigating between screens, react-query seems to struggle, as it ends up returning an undefined . To give a better perspective of...
Read more >
useRoute - React Navigation
useRoute is a hook which gives access to route object. It's useful when you cannot pass the route prop into the component directly,...
Read more >
Tutorial v6.6.1 - React Router
Welcome to the tutorial! We'll be building a small, but feature-rich app that lets you keep track of your contacts. We expect it...
Read more >
Suspense for Data Fetching (Experimental) - React
We call this approach “fetch-on-render” because it doesn't start fetching until after the component has rendered on the screen. This leads to a...
Read more >
How to handle navigation in your app with React Router Link
In non-React apps, the navigation between pages is done through <a> tags. The same can be used in React, but the problem with...
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