Repository navigation
fix: keep Build.isBrowser branches removable in hydrate builds - #761
Open
Unipro-DanMunn wants to merge 1 commit into
Open
Unipro-DanMunn wants to merge 1 commit into
Unipro-DanMunn wants to merge 1 commit into
Conversation
Since 2.2.2 the Stencil subscription copied the `@stencil/core` namespace into a variable. That makes Rollup keep the whole module object, so it can no longer fold `Build.isBrowser` to `false` in Stencil's hydrate build, and browser-only modules imported behind that check get bundled into the hydrate app. Read `forceUpdate` and `getRenderingRef` straight off the namespace instead, which keeps tolerating a `@stencil/core` without those exports. Adds a test that builds a small Stencil app with a `dist-hydrate-script` output and checks the output.
3 tasks done
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.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build) was run locally and any changes were pushednpm test) were run locally and passednpm run prettier) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Since 2.2.2,
src/subscriptions/stencil.tscopies the@stencil/corenamespace into a variable (const core = StencilCore). Rollup then keeps the whole module object, so it can no longer foldBuild.isBrowsertofalsein Stencil's hydrate build. Any browser-only module imported behindif (Build.isBrowser)is bundled into the hydrate app and runs when it loads, sorenderToStringcan throw (for exampledocument.createTreeWalker is not a function).GitHub Issue Number: #760
What is the new behavior?
forceUpdateandgetRenderingRefare read straight off the namespace (StencilCore.forceUpdate), which Rollup resolves to the individual exports, soBuild.isBrowserbranches are removed from hydrate builds again.@stencil/corewithout these exports still gets an empty subscription instead of a missing-export error.test/hydrate.test.ts: it bundles the store as it's published, installs it into a small Stencil app (test/hydrate-app) with adist-hydrate-scriptoutput, builds that app, and checks that a module imported behindBuild.isBrowserisn't in the hydrate app.Does this introduce a breaking change?
Testing
main(module imported behind Build.isBrowser was bundled into the hydrate app) and passes with this change.npm test: 65 tests pass, and Prettier reports no changes.import * as StencilCorestops Rollup removingBuild.isBrowserbranches from the hydrate app #760 (https://github.com/Unipro-DanMunn/stencil-store-hydrate-repro, Stencil 4.45.2) against this branch's build. The browser-only module is no longer inhydrate/index.mjs, andrenderToStringsucceeds and renders declarative shadow DOM.Other information
The test installs the store into the fixture's
node_modulesinstead of importing it fromsrc, because the bug only reproduces when Stencil consumes the store as pre-built JavaScript. The fixture has its ownpackage.jsonso TypeScript doesn't resolve@stencil/storeto this repo's source through package self-reference.