-
Notifications
You must be signed in to change notification settings - Fork 406
feat: add block data and client scripts and block props #459
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
Open
stravo1
wants to merge
138
commits into
frappe:develop
Choose a base branch
from
stravo1:block-data-script
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
used the rawStylesSection as a template to create the props section to maintain consistency but forgot to update the name
previously, block props relied on blockIds to manage inheritance. This caused issues when using components - each component instance generated new blockIds for its blocks, breaking prop references that still pointed to the original component blockIds. maintaining and updating these blockId dependencies became increasingly complex and error-prone. this commit removes the dependency on blockIds entirely. Props are now identified by their names, and a stack-based approach is used to resolve inherited values. the system now behaves similarly to variable scoping in programming languages - where inherited props take the value of the nearest ancestor with the same prop name in the faimly tree (block scoping in programming)
green shows that inherited prop is valid, i.e., there is an ancestor who has that prop and can be inherited while red shows that the inherited prop is invalid and no ancestor was found having that prop
… edit block scripts
have NOT intentionally put all script content in one script tag as if here is an error in one of the blockScripts then the remaining/following blockScripts also fail to execute
blocks which are children of such repeater get some default props to access the looping items
this is because props which are dynamic and depend on loop variables as in for eg {{ key_item.val }} go out of the loop block {% for item in arr %} ... {% endfor %} when all scripts are added in one place
- getPropValue and getValueForInheritedProp now returns default values for std. props in specific conditions - defaultValue in StringOptions updates properly - No dynamic values message shown in required conditions - removing defaultValue from standardOptions and moving it to standardOptions.options
could not edit array items as they would update props and that would trigger recalculation of block data and thus re-render the editor and steal focus from the array editor.
`False or 'undefined'` would result in 'undefined' even though False is the actual value
- `this` is now suggested in block js completions - `props` is now suggested in both block python and js completions - actual props are also suggested in completions - along side `data`, page_data now also accepts `page`
This was referenced Jan 6, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #459 +/- ##
===========================================
- Coverage 49.26% 48.64% -0.63%
===========================================
Files 28 28
Lines 2176 2393 +217
===========================================
+ Hits 1072 1164 +92
- Misses 1104 1229 +125 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- refreshing would fix the issue - happened because the component props were directly mutated
previous solution was wrong as it suffered from the same issue of being re-used as classes and blockIds, solved using loop.index
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.
This PR introduces block props and block client scripts (JS) and block data scripts (Py).
Each block now has three new properties: Block Props and Block Client Scripts and Block Data Scripts.
Props:
Props work similarly to those found in component-based JavaScript frameworks such as Vue or React. They serve as an interface between the “outside world” and the block scripts (both client and data scripts).
There are two types of props:
Props are not passed down to child blocks by default. However, users can explicitly choose which props should be propagated. Any prop that is marked to be passed down becomes accessible to all descendant blocks of the block that declares it. These props can also be used as dynamic values wherever dynamic values are supported, such as in Text blocks.
Standard Block Props
These are special type of block props which can be used in Components. Std. Block props can be declared on the root block of a component. They can be of various types such as string, number, boolean, arrays (
string[]) and objects (Map<string, string>), unlike non-std. props which are always of type string. They differ from from non-std. props in two primary ways:Std. props of type array and object can also be used as keys for Repeaters/Collections to loop over their values. In such cases, for std. prop of type object, all blocks - which are repeated - are assigned two default props named
keyandvaluewhich hold the value of the key-value pairs of the object being looped over. Same goes for std. prop of type array, and in such case there is only one default prop nameditem.Adding block props:
Adding std. props to root of component:
Different types of std. props:
Some std. props with default values (here Name and Type are same, that is for demonstration purpose) :
How they appear when used in a page:
Block Data Script:
These are Python code snippets associated with an individual block, unlike Data Script which applies to the entire page. Block data scripts can be used like Page Data scripts to get dynamic values during SSR.
Within Block Data Script, two special keywords are available:
block: Similar todatain page data scripts, we haveblockin block data scripts. It can be used to assign dynamic values which can be used in the block. Also all block data are passed down, so once a block assigns a dynamic value, it is accessible to all its successors. A successor block can re-assign a dynamic value in it's own block data script in which case the nearest assignment of the value is used, similar to how block scoping/variable shadowing works.props: Provides access to the properties passed to the block.Assigning block data script:
Using the cumulative toggle to view all the block data being passed to the current block.
Block Client Script:
These are JavaScript code snippets associated with an individual block, unlike Client Scripts which apply to an entire page.
Block Scripts make it easier to manage reactivity by eliminating the need for multiple Client Scripts and by localizing logic to the block itself.
Within a Block Script, two special keywords are available:
this: Refers directly to the DOM node corresponding to the block.Example:
attaches an event listener to the block itself.
props: Provides access to the properties passed to the block.Some examples:
Screen.Recording.2026-01-06.at.11.14.35.AM.mov
Name,Description,Image URL, etc. When this component is used in a page, the user simply fills those inputs and the Profile Card is ready.Screen.Recording.2025-11-26.at.11.06.33.PM.mp4
Linksin which user puts a list of title and urls.Screen.Recording.2025-11-26.at.11.08.47.PM.mp4
Screen.Recording.2025-11-27.at.12.11.44.PM.mp4