Skip to content
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): forceUpdate calls only execute when in a browser env #4591

Merged
merged 6 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/runtime/test/globals.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ describe('globals', () => {
});

it('build values', () => {
expect(Build.isBrowser).toBe(false);
expect(Build.isBrowser).toBe(true);
expect(Build.isDev).toBe(true);
expect(Build.isTesting).toBe(true);
expect(Build.isServer).toBe(false);
});

it('Env is defined', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/update-component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BUILD, NAMESPACE } from '@app-data';
import { consoleError, doc, getHostRef, nextTick, plt, win, writeTask } from '@platform';
import { Build, consoleError, doc, getHostRef, nextTick, plt, win, writeTask } from '@platform';
import { CMP_FLAGS, HOST_FLAGS } from '@utils';

import type * as d from '../declarations';
Expand Down Expand Up @@ -336,7 +336,7 @@ export const postUpdateComponent = (hostRef: d.HostRef) => {
};

export const forceUpdate = (ref: any) => {
if (BUILD.updatable) {
if (BUILD.updatable && Build.isBrowser) {
const hostRef = getHostRef(ref);
const isConnected = hostRef.$hostElement$.isConnected;
if (
Expand Down
4 changes: 2 additions & 2 deletions src/testing/platform/testing-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as d from '@stencil/core/internal';

export const Build: d.UserBuildConditionals = {
isDev: true,
isBrowser: false,
isServer: true,
isBrowser: true,
isServer: false,
Comment on lines +5 to +6
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed to make these changes for unit tests leveraging forceUpdate to pass. No other tests started to fail with this change and the newSpecPage helper uses the lazy build which would traditionally have isBrowser: true. So, I believe this is a low-risk change

Copy link
Contributor

Choose a reason for hiding this comment

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

tbh I don't know a whole lot about what the consequences of this could be, but this makes sense to me 👍

isTesting: true,
};
Loading