-
Notifications
You must be signed in to change notification settings - Fork 795
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
fix(runtime): initialize custom elements even when there is no styles #4296
Merged
+29
−9
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2bb7f25
remove top-level check gating init logic based on build flags
tanner-reits 2386843
add small test to check initialized flag
tanner-reits 25e98fe
prettier because I don't have it auto-format spec files 🤦♂️
tanner-reits 353f1cf
Merge branch 'main' into treits/fix/custom-elements-watchers
tanner-reits 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
This file contains 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 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 { getHostRef } from '@platform'; | ||
import { Component } from '@stencil/core'; | ||
import { newSpecPage } from '@stencil/core/testing'; | ||
|
||
import { HOST_FLAGS } from '../../utils'; | ||
|
||
describe('initialize component', () => { | ||
@Component({ | ||
tag: 'cmp-a', | ||
}) | ||
class CmpA {} | ||
|
||
it('should mark the component as initialized', async () => { | ||
const page = await newSpecPage({ | ||
components: [CmpA], | ||
html: `<cmp-a><cmp-a>`, | ||
}); | ||
|
||
const hostFlags = getHostRef(page.root).$flags$; | ||
expect(hostFlags & HOST_FLAGS.hasInitializedComponent).toBe(HOST_FLAGS.hasInitializedComponent); | ||
}); | ||
}); |
This file contains 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
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.
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.
At first I thought this was a split/shift of the
if
statement, but looking a little closer, this appears to be subtly different:Can you help me understand the reasoning behind the change from
hydrateServerSide
->hydrateClientSide
?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.
So there are two
if
checks there actually. The top-most check originally had the check containingBUILD.hydrateServerSide
, but I removed the first part of that check because:BUILD.style
was preventing that block of code to run fordist-custom-elements
builds when the component did not have an associated stylesheet. But, if we just removed that portion of the check, then it would never execute fordist-custom-elements
buildsThe second
if
statement is nested directly in that first block. I did not change that conditional or it's code block at all except for pulling out the line that sets thehasInitializedComponent
flag on the hostRef since that exact code happened in both theif
andelse
blocks.Let me know if that doesn't make sense or you think my reasoning is wrong @rwaskiewicz
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.
So if I'm understanding correctly, the change is basically to make the outer check only whether the component has been previously initialized (
hostRef.$flags$ & HOST_FLAGS.hasInitializedComponent
) because the code within the block for thatif
is stuff we always want to run, regardless of whether this is a lazy load, hydrate build, etc.Then within that block we have two different code paths, one for
BUILD.lazyLoad || BUILD.hydrateClientSide
and one for everything else (which is if I understand correctly where we'll go when dealing with adist-custom-elements
build).The overall logic I think makes sense to me, something like 'did we initialize? if not, let's initialize. then, what kind of component are we dealing with?' and then we do what's specific to different ways to initialize a component.
Is that an accurate summary? If so I think this looks good to me. I also tried out running this change in the reproduction and confirmed that it works correctly.
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.
Yep! That's exactly 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.
Ah OK - thank you both!