Fix Tree view not working with Server Components (JSX adapter)#198
Open
Strajk wants to merge 1 commit intoinfi-pc:masterfrom
Open
Fix Tree view not working with Server Components (JSX adapter)#198Strajk wants to merge 1 commit intoinfi-pc:masterfrom
Strajk wants to merge 1 commit intoinfi-pc:masterfrom
Conversation
|
@Strajk is attempting to deploy a commit to the Michael Musil's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Tree view not working with Server Components (JSX adapter)
Problem
Tree view was not clickable when using LocatorJS with:
@locator/webpack-loaderwith TurbopackWhat worked: Click-to-source on elements directly on the page ✅
What didn't work: Clicking elements in the tree view panel ❌
Root Cause
Two issues were discovered:
1. Missing
window.__LOCATOR_DATA__for Server ComponentsThe webpack loader adds
data-locatorjsattributes to the DOM:The babel plugin also injects
window.__LOCATOR_DATA__with component metadata, but this code only runs on the client:For Server Components, there's no
windowon the server, so__LOCATOR_DATA__is never populated. The tree view relied on this data forgetSource()andgetComponent(), causing them to returnnull.2.
callLinkvsdefinitionLinkmismatchThe
TreeNodeElementViewcomponent checked forcallLinkto make component labels clickable:But the JSX adapter returns
definitionLinkinstead:Solution
Updated
TreeNodeElementView.tsxto:Add DOM attribute fallback: Extract source info directly from
data-locatorjsattribute whengetSource()returns nullUse
definitionLinkas fallback: Check bothcallLinkanddefinitionLinkfor component linksResult
__LOCATOR_DATA____LOCATOR_DATA__)Tree view now works for Server Components by reading source location directly from the DOM
data-locatorjsattribute.