Skip to content

Commit

Permalink
Merge pull request #751 from adobe/fix-750
Browse files Browse the repository at this point in the history
fix: account for url's with fragments when adding nocache query param
  • Loading branch information
dylandepass authored May 31, 2024
2 parents d3ae483 + 7487868 commit 48e60cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/extension/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4083,8 +4083,9 @@ import sampleRUM from './rum.js';
const liveDomains = ['aem.live', 'hlx.live'];
if (cacheBust
&& !(targetEnv === 'prod' && !liveDomains.some((domain) => envUrl.includes(domain)) && this.config.transient)) {
const separator = envUrl.includes('?') ? '&' : '?';
envUrl = `${envUrl}${separator}nocache=${Date.now()}`;
const url = new URL(envUrl);
url.searchParams.set('nocache', Date.now());
envUrl = url.toString();
}

// switch or open env
Expand Down
1 change: 1 addition & 0 deletions test/SidekickTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export class SidekickTest extends EventEmitter {
method: req.method,
headers: req.headers,
url,
urlFragment: req.urlFragment,
};
if (this.requestHandler) {
const r = await this.requestHandler(reqObj);
Expand Down
21 changes: 21 additions & 0 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ describe('Test publish plugin', () => {
assert.ok(navigated.startsWith('https://blog.adobe.com/en/topics/bla?nocache='), 'Redirect not sent');
}).timeout(IT_DEFAULT_TIMEOUT);

it('Publish works with fragment and nocache', async () => {
const setup = new Setup('blog');
nock.sidekick(setup);
nock.admin(setup);
nock('https://admin.hlx.page')
.post('/live/adobe/blog/main/en/topics/bla')
.reply(200);
const { requestsMade } = await new SidekickTest({
browser,
page,
plugin: 'publish',
url: 'https://main--blog--adobe.hlx.page/en/topics/bla#fragment',
waitNavigation: 'https://blog.adobe.com/en/topics/bla?nocache=',
}).run();
const navigationRequest = requestsMade.find((r) => r.url.includes('https://blog.adobe.com/en/topics/bla?nocache='));
assert.equal(
navigationRequest.urlFragment,
'#fragment',
);
}).timeout(IT_DEFAULT_TIMEOUT);

it('Publish plugin also publishes dependencies', async () => {
const setup = new Setup('blog');
nock.sidekick(setup);
Expand Down

0 comments on commit 48e60cb

Please sign in to comment.