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(v6.4.0 RC): conditionally remove SSELink from the bundle #9401

Merged
merged 7 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/core/config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ module.exports = (webpackEnv) => {
filename: 'static/media/[name].[contenthash:8][ext]',
},
},
// (8)
!redwoodConfig.experimental.realtime.enabled && {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will have to rethink of to toggle. Late PR's will introduce a graphql toml config section, so could put there as realtime or even useSSE?

test: require.resolve('@redwoodjs/web/dist/apollo/sseLink'),
use: require.resolve('null-loader'),
},
].filter(Boolean),
},
],
Expand Down
3 changes: 3 additions & 0 deletions packages/project-config/src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ describe('getConfig', () => {
"enabled": false,
"wrapApi": true,
},
"realtime": {
"enabled": false,
},
"rsc": {
"enabled": false,
},
Expand Down
6 changes: 6 additions & 0 deletions packages/project-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export interface Config {
rsc: {
enabled: boolean
}
realtime: {
enabled: boolean
}
}
}

Expand Down Expand Up @@ -193,6 +196,9 @@ const DEFAULT_CONFIG: Config = {
rsc: {
enabled: false,
},
realtime: {
enabled: false,
},
},
}

Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ export default function redwoodPluginVite(): PluginOption[] {
id: /@redwoodjs\/router\/dist\/splash-page/,
},
]),
!rwConfig.experimental.realtime.enabled &&
removeFromBundle([
{
id: /@redwoodjs\/web\/dist\/apollo\/sseLink/,
},
]),
react({
babel: {
...getWebSideDefaultBabelConfig({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function removeFromBundle(

// Currently configured for CJS only.
const EMPTY_MODULE = {
code: `module.exports = null`,
code: `module.exports = {}`,
}

export function excludeOnMatch(modulesToExclude: ModulesToExclude, id: string) {
Expand Down
39 changes: 21 additions & 18 deletions packages/web/src/apollo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type {

export { useCache }

export { fragmentRegistry, registerFragment, registerFragments, SSELink }
export { fragmentRegistry, registerFragment, registerFragments }
dthyresson marked this conversation as resolved.
Show resolved Hide resolved

export type ApolloClientCacheConfig = apolloClient.InMemoryCacheConfig

Expand Down Expand Up @@ -212,23 +212,26 @@ const ApolloProviderWithFetchConfig: React.FunctionComponent<{

// Our terminating link needs to be smart enough to handle subscriptions, and if the GraphQL query
// is subscription it needs to use the SSELink (server sent events link).
const httpOrSSELink = apolloClient.split(
({ query }) => {
const definition = getMainDefinition(query)

return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
)
},
new SSELink({
url: uri,
auth: { authProviderType, tokenFn: getToken },
httpLinkConfig,
headers,
}),
httpLink
)
const httpOrSSELink =
typeof SSELink !== 'undefined'
? apolloClient.split(
({ query }) => {
const definition = getMainDefinition(query)

return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
)
},
new SSELink({
url: uri,
auth: { authProviderType, tokenFn: getToken },
httpLinkConfig,
headers,
}),
httpLink
)
: httpLink

// The order here is important. The last link *must* be a terminating link like HttpLink or SSELink.
const redwoodApolloLinks: RedwoodApolloLinks = [
Expand Down
65 changes: 36 additions & 29 deletions tasks/smoke-tests/shared/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,50 @@ import type { PlaywrightTestArgs } from '@playwright/test'
export async function smokeTest({ page }: PlaywrightTestArgs) {
await page.goto('/')

// Check that the blog posts are being loaded.
// Avoid checking titles because we edit them in other tests.
await page.textContent('text=Meh waistcoat succulents umami')
await page.textContent('text=Raclette shoreditch before they sold out lyft.')
await page.textContent(
'text=baby single- origin coffee kickstarter lo - fi paleo skateboard.'
)

// Check that the blog posts load. We're deliberately not checking their titles because we edit them in other tests.
await expect(
page.getByText(
'Meh waistcoat succulents umami asymmetrical, hoodie post-ironic paleo chillwave '
)
).toBeVisible()
await expect(
page.getByText(
'Raclette shoreditch before they sold out lyft. Ethical bicycle rights meh prism '
)
).toBeVisible()
await expect(
page.getByText(
"I'm baby single- origin coffee kickstarter lo - fi paleo skateboard.Tumblr hasht"
)
).toBeVisible()

// CSS checks. We saw this break when we switched bundlers, so while it's not comprehensive, it's at least something.
// While playwright recommends against using locators that are too-closely tied to the DOM, `#redwood-app` is a stable ID.
const bgBlue700 = 'rgb(29, 78, 216)'
expect(
await page
.locator('#redwood-app > header')
.evaluate((e) => window.getComputedStyle(e).backgroundColor)
).toBe(bgBlue700)
expect(page.locator('#redwood-app > header')).toHaveCSS(
'background-color',
bgBlue700
)

const textBlue400 = 'rgb(96, 165, 250)'
expect(
await page
.locator('header a')
.filter({ hasText: 'Redwood Blog' })
.evaluate((e) => window.getComputedStyle(e).color)
).toBe(textBlue400)

// Click text=About
await page.click('text=About')
expect(await page.getByRole('link', { name: 'Redwood Blog' })).toHaveCSS(
'color',
textBlue400
)

// Check the about page.
await page.getByRole('link', { name: 'About', exact: true }).click()
expect(page.url()).toBe('http://localhost:8910/about')

await page.textContent(
'text=This site was created to demonstrate my mastery of Redwood: Look on my works, ye'
await page.getByText(
'This site was created to demonstrate my mastery of Redwood: Look on my works, ye'
)
// Click text=Contact
await page.click('text=Contact')

// Check the contact us page.
await page.getByRole('link', { name: 'Contact Us' }).click()
expect(page.url()).toBe('http://localhost:8910/contact')

// Click text=Admin
await page.click('text=Admin')
// Check the admin page.
await page.getByRole('link', { name: 'Admin' }).click()
expect(page.url()).toBe('http://localhost:8910/posts')
}

Expand Down
Loading