-
Notifications
You must be signed in to change notification settings - Fork 12
feat: add LocationSensor helper component for next AppRouter and PagesRouter #789
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
feat: add LocationSensor helper component for next AppRouter and PagesRouter #789
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: d795cc6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
aaa9042 to
9640193
Compare
packages/react/src/modules/guide/components/LocationSensor/NextAppRouter.tsx
Show resolved
Hide resolved
d9253b5 to
d795cc6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #789 +/- ##
==========================================
- Coverage 66.06% 65.84% -0.22%
==========================================
Files 185 188 +3
Lines 7706 7753 +47
Branches 950 950
==========================================
+ Hits 5091 5105 +14
- Misses 2591 2624 +33
Partials 24 24
|

Description
Adds a couple Next js specific helper components for detecting location changes for the guide client, rather than auto detecting from the window object, so activation evaluations can run properly.
We've observed the latter (default) not working in our dashboard in prod currently, even though it works fine when running locally. It appears that Next js is doing something differently in production builds, where it's potentially caching history methods early in production (for optimizations?) and bypassing the monkey patching (pushState/replaceState) we are doing on the window object during a guide client initialization.
These specific helpers are meant to be used inside the KnockGuideProvider, which calls
setLocationon the provided client using the nextjs router object. For example:Note
Adds Next.js App/Pages Router LocationSensor components and updates the guide client to explicitly remove window-based listeners, with exports and peer deps adjusted.
LocationSensorNextAppRouterandLocationSensorNextPagesRoutercomponents to track route changes via Next.js routers and callclient.setLocation.KnockGuideLocationSensorNextAppRouterandKnockGuideLocationSensorNextPagesRouterfrompackages/react/src/index.tsand guide module indexes.removeLocationChangeEventListeners()and uses it incleanup().handleLocationChange; maintains and restores history patches when removing listeners.nextas a peer dependency and includes it in devDependencies for@knocklabs/react.Written by Cursor Bugbot for commit d795cc6. This will update automatically on new commits. Configure here.