Skip to content

Conversation

Spring3
Copy link
Collaborator

@Spring3 Spring3 commented Sep 16, 2025

Purpose

Approach

@Spring3 Spring3 self-assigned this Sep 16, 2025
Copy link

vercel bot commented Sep 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nextjs-marketing-demo-bug-test Building Building Preview Sep 26, 2025 2:34pm
3 Skipped Deployments
Project Deployment Preview Updated (UTC)
experience-builder-test-app Ignored Ignored Sep 26, 2025 2:34pm
studio-nextjs-marketing-demo Ignored Ignored Sep 26, 2025 2:34pm
studio-react-vite-template Ignored Ignored Sep 26, 2025 2:34pm

@Spring3 Spring3 changed the title feat: render prebinding data in preview mode feat: render prebinding data in preview mode [SPA-2923] Sep 16, 2025
@Spring3 Spring3 force-pushed the feat/preview-render-prebinding-data branch from 0ff6e60 to 3b3f3af Compare September 17, 2025 13:34
@Spring3 Spring3 marked this pull request as ready for review September 19, 2025 15:59
@Spring3 Spring3 requested a review from a team as a code owner September 19, 2025 15:59
@Spring3 Spring3 requested review from duruld and Chaoste and removed request for a team September 19, 2025 15:59
@Ollie-H Ollie-H self-requested a review September 23, 2025 08:39
@Spring3 Spring3 force-pushed the feat/preview-render-prebinding-data branch from 52a41c3 to 06403bc Compare September 24, 2025 14:32
@@ -0,0 +1,547 @@
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to keep a minimal version of the prebindingManager that only includes:

  • storePrebindingDefinitions
  • storeParameterDefinitions
  • getHoistedParameterByNodeId

Given that the one in the Web App has already diverged from this one, it just makes things more complicated to keep them in sync.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it makes sense 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will align it with the latest version from the web app I think

Comment on lines +95 to +99
pattern: {
nodeIdOnPattern: 'test-custom-component-id',
parentPatternNodeId: undefined,
prefixedNodeId: 'test-custom-component-id',
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to point out that I decided to keep these properties just in case, but they aren't used anywhere. So we can clean them up. I'm happy to hear your opinions

* @param indexedNodeId - The indexed node ID to resolve the parameterId for
* @returns string - The resolved parameterId - will be from "root" in patterns or the parent pattern node in experiences
*/
public static getHoistedIdForParameterId(parameterId: string, indexedNodeId: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need the latest version with the fix applied from this morning?

Copy link
Collaborator Author

@Spring3 Spring3 Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because indexing here was done slightly differently (and here.) we purely pass the pattern node ids chain joined with a separator and never actually pass the regular node ids

so getHoistedIdForParameterId is always called with the pattern ids and never with the component node ids. shouldUsePrebinding checks if the component's property appears in the native variableMapping and if it does - it takes its value by the hoisted parameter id

Copy link
Collaborator Author

@Spring3 Spring3 Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't have the editor functionality at this point, we don't care of the component node ids on the rendering path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Hopefully we don't need to touch it much but the fact they are mostly identical could get confusing why/when they should diverge.

Comment on lines 67 to 73
const patternRootNodeIdsChain = useMemo(() => {
if (isPatternNode) {
// Pattern nodes are chained without a separator (following the format for prebinding/parameters)
return `${parentPatternRootNodeIdsChain}${rawNode.id}`;
return [...parentPatternRootNodeIdsChain, rawNode.id!];
}
return parentPatternRootNodeIdsChain;
}, [isPatternNode, parentPatternRootNodeIdsChain, rawNode.id]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what is used in getHoistedIdForParameterId method and as you can see, we include the new id only if it's a nested pattern.

Since each node of the pattern has it's own unique id in the layout, we don't get a collision when having 2 instances of the same nested pattern.

We should migrate to use node ids as well on the web app side

Copy link
Contributor

@Ollie-H Ollie-H left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tested locally and all working with all the main scenarios.

return;
}

const fieldPath = variableMapping.pathsByContentType[contentTypeId].path;
Copy link
Contributor

@SofiaMargariti SofiaMargariti Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not in your changes, but this will fail if there is no mapping for a specific CT. It's the scenario where I am mapping:

  • CT-A to:
    • propA
    • propB
  • CT-B to:
    • prop C

And my selected source is of type CT-A. When resolving mapping for propC, variableMapping.pathsByContentType[contentTypeId] will be undefined and this will throw. Adding some optional chaining should cover this case.

Copy link
Contributor

@SofiaMargariti SofiaMargariti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me a while to test this. The code looks good overall, just an edge-case that I noticed and I've comment above!

@Spring3
Copy link
Collaborator Author

Spring3 commented Sep 26, 2025

Sorry it took me a while to test this. The code looks good overall, just an edge-case that I noticed and I've comment above!

It would be nice if someone would cover it in a follow-up. Let's drop a ticket for visibility

@Spring3 Spring3 merged commit e1ab24d into development Sep 26, 2025
18 checks passed
@Spring3 Spring3 deleted the feat/preview-render-prebinding-data branch September 26, 2025 15:50
@SofiaMargariti
Copy link
Contributor

Sorry it took me a while to test this. The code looks good overall, just an edge-case that I noticed and I've comment above!

It would be nice if someone would cover it in a follow-up. Let's drop a ticket for visibility

No worries, I will open a quick PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants