-
Notifications
You must be signed in to change notification settings - Fork 616
fix(fast-html): fix event bindings inside f-when not firing after hydration #7327
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
mohamedmansour
wants to merge
14
commits into
microsoft:main
Choose a base branch
from
mohamedmansour:fix/hydration-under-conditions
base: main
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.
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d681f8e
fix: Fix event bindings inside f-when not firing after hydration
mohamedmansour 8a6e756
add more tests
mohamedmansour eb09ecd
Fix tests
mohamedmansour ea1a800
Apply suggestions from code review
mohamedmansour be54d2c
Merge branch 'main' into fix/hydration-under-conditions
mohamedmansour 53982ca
fix(fast-html): bind event handlers to host element inside repeat dir…
d2d473e
Update packages/fast-element/src/templating/html-binding-directive.ts
mohamedmansour 8d56ed5
Add f-when false test case
mohamedmansour c4a0b81
Merge branch 'fix/hydration-under-conditions' of https://github.com/m…
mohamedmansour 3c7b703
Merge remote-tracking branch 'origin/pr-7327' into fix/hydration-unde…
mohamedmansour 5eba2ed
fix(fast-html): respect explicit falsy values in f-when during hydration
mohamedmansour 96d7c75
Merge remote-tracking branch 'upstream/main' into fix/hydration-under…
mohamedmansour b062869
revert: remove repeat event binding context walk-up
mohamedmansour 37fd13a
refactor: merge when-false-explicit fixture into when-event
mohamedmansour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-fast-element-ccc364c3-3d9a-4477-a877-812d7fc72bff.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "", | ||
| "packageName": "@microsoft/fast-element", | ||
| "email": "hello@mohamedmansour.com", | ||
| "dependentChangeType": "none" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@microsoft-fast-html-1cbbfa63-0099-407f-9cd2-36fe3f44f3c3.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "", | ||
mohamedmansour marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "packageName": "@microsoft/fast-html", | ||
| "email": "hello@mohamedmansour.com", | ||
| "dependentChangeType": "none" | ||
| } | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title></title> | ||
| <script type="module" src="./main.ts"></script> | ||
| </head> | ||
| <body> | ||
| <!-- Template uses "serverOnly" which is NOT a property on test-element. | ||
| This simulates <if condition="serverOnly"> where the server state has serverOnly=true | ||
| but the client class doesn't know about it. --> | ||
| <f-template name="test-element"> | ||
| <template><f-when value="{{serverOnly}}"><button @click="{handleClick()}">Click me</button></f-when></template> | ||
| </f-template> | ||
| <!-- SSR: condition was true, so button is rendered with hydration markers --> | ||
| <test-element id="when-event-show"> | ||
| <template shadowrootmode="open"><!--fe-b$$start$$0$$MRl5Rw6tl3$$fe-b--><button data-fe-b-0>Click me</button><!--fe-b$$end$$0$$MRl5Rw6tl3$$fe-b--></template> | ||
| </test-element> | ||
| </body> | ||
| </html> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { RenderableFASTElement, TemplateElement } from "@microsoft/fast-html"; | ||
| import { FASTElement } from "@microsoft/fast-element"; | ||
|
|
||
| // This element intentionally does NOT define "serverOnly" as a property. | ||
| // The f-when condition references "serverOnly" which only exists in server state, | ||
| // simulating the real-world scenario where <if condition="..."> uses server-only data. | ||
| class TestElement extends FASTElement { | ||
| public clickCount: number = 0; | ||
|
|
||
| public handleClick = (): void => { | ||
| this.clickCount++; | ||
| console.log("clicked:" + this.clickCount); | ||
| }; | ||
| } | ||
| RenderableFASTElement(TestElement).defineAsync({ | ||
| name: "test-element", | ||
| templateOptions: "defer-and-hydrate", | ||
| }); | ||
|
|
||
| TemplateElement.define({ | ||
| name: "f-template", | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <f-when value="{{serverOnly}}"><button @click="{handleClick()}">Click me</button></f-when> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "serverOnly": true | ||
| } |
23 changes: 23 additions & 0 deletions
23
packages/fast-html/test/fixtures/when-event/when-event.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { expect, test } from "@playwright/test"; | ||
|
|
||
| test.describe("f-when with event binding", async () => { | ||
| test("event binding inside f-when should fire after hydration", async ({ page }) => { | ||
| await page.goto("/fixtures/when-event/"); | ||
|
|
||
| const customElement = page.locator("#when-event-show"); | ||
|
|
||
| // Button should be visible (SSR rendered, condition true) | ||
| const button = customElement.locator("button"); | ||
| await expect(button).toHaveText("Click me"); | ||
|
|
||
| // Click the button - event binding should work | ||
| await button.click(); | ||
|
|
||
| // Verify the click handler fired | ||
| await expect(customElement).toHaveJSProperty("clickCount", 1); | ||
|
|
||
| // Click again to confirm repeated clicks work | ||
| await button.click(); | ||
| await expect(customElement).toHaveJSProperty("clickCount", 2); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.