-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(solidjs): Add solid router instrumentation #12263
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the PR description with how this is meant to be set up?
packages/solidjs/package.json
Outdated
@@ -54,6 +55,9 @@ | |||
"solid-js": "1.8.11", | |||
"vite-plugin-solid": "^2.8.2" | |||
}, | |||
"optionalDependencies": { | |||
"@solidjs/router": "0.13.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: should this be a more liberal range? Actually now that I think about it, should we also expand the range for solid-js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd do ^1.8.0 for solid-js
. For the router it's harder because 🤷 damn 0.x versions 😬 at the very least we should also do ^0.13.3
but this means that for every minor release they do (e.g. 0.14.0) we'll have to update the SDK accordingly to match this 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the docs for the router:
The docs are based on Solid Router v0.10.x. To use this version, you need to have Solid v1.8.4 or later installed.
Should I downgrade to that and see if it still runs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That puts us at 1.8.4
as minimum for solid-js. We can probably support a lower version if we have some kind of warnings inside solidrouter.ts
if it's used with a version lower than 1.8.4
. Is that possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's fine to say this is ^1.8.4
too, this is greenfield so let's start with support that makes it reasonably easy for us! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to ^1.8.4
.
packages/solidjs/src/solidrouter.ts
Outdated
import { createComponent } from 'solid-js/web'; | ||
import { DEBUG_BUILD } from './debug-build'; | ||
|
||
const CLIENTS_WITH_INSTRUMENT_NAVIGATION: Client[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a WeakMap
/WeakSet
so we don't need to iterate the array, and we can GC the client if need be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Added |
_useBeforeLeave = useBeforeLeave; | ||
_useLocation = useLocation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we directly import and use useLocation
and useBeforeLeave
from solidjs/router
instead?
I hope we don't have to await import
it to make the optionalDependencies
work properly 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we can't. I spent the entire day trying to figure this out with the help of @lforst - but basically the compiler detects that these hooks are used outside of the router and the invariant that detects this is baked into the bundle.
The router context is different :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang that sucks :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, was hoping it would work. Maybe we can talk to the maintainer to find some workaround.
export default makeNPMConfigVariants( | ||
makeBaseNPMConfig({ | ||
packageSpecificConfig: { | ||
external: ['solid-js', 'solid-js/web', '@solidjs/router'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, is this needed? shouldn't this be automatically marked as external? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might not be needed. I didn't have solid-js
in there before and everything built and worked fine. Will try to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed, don't need. Removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty confident solid-js/web
is still needed because it is not added to external
because it is not inside any dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not in the build output, I double-checked again.
packages/solidjs/package.json
Outdated
@@ -54,6 +55,9 @@ | |||
"solid-js": "1.8.11", | |||
"vite-plugin-solid": "^2.8.2" | |||
}, | |||
"optionalDependencies": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is optionalDependencies
the best thing for this? What about making this an optional peer dependency? (not sure how well supported etc. this is though...)
Because I guess optionalDependencies
means this will generally always be installed along by the SDK, right...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also realized this. I thought optionalDependencies would be just like a "soft" peer dep but package managers will actually try to install these. We should simply document the version requirements instead in JS Doc and in the actual docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional peer dependencies are a npm 7.x thing. Not sure if that's too high for us.
As for optionalDependencies
- I've only tried with a tarball, but solid router was not pulled in if the user didn't already have it and there were no warnings about requiring it either. Or am I misunderstanding your question?
edit: nvm I'm a liar. It did pull in solid router as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean maybe it is fine to have it as optionalDependencies
, just feels like a non-ideal solution 😬 I guess this is why in react we do not depend on react-router at all 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only use types from solid router, I could vendor these in, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think that's probably the best solution here! We also do that in other places (it has it's own set of problems obviously, but I think this is the best trade off 🤔 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only add dependencies as devDependencies
. Everything else only has downsides and no upsides (that I am aware of).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vendored the types in and removed the dep on solid router.
packages/solidjs/src/solidrouter.ts
Outdated
afterAllSetup(client) { | ||
integration.afterAllSetup(client); | ||
|
||
const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Do we actually need this? Is this different from just letting the base browserTracingIntegration
create the pageload span? If not, we can just pass instrumentPageLoad
through (instead of forcing this to false) and only handle the navigation span in a custom way here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay that the origin won't be auto.pageload.solidjs.solidrouter
in that case? Or should I be getting and updating the pageload span?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is fine, this is really just for ourselves :)
d50c649
to
04d2dd3
Compare
size-limit report 📦
|
f7f60ce
to
c008bac
Compare
956b46d
to
9354905
Compare
…cingIntegration's
9354905
to
5b74d49
Compare
I'd like to get some feedback on the general approach here. Unit and E2E tests would follow either in a follow up PR or after getting the approach validated here.
I've tested this in a sample app locally and it works on my machine(tm).
To use this integration: